FIRDynamicLinkNetworking.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "FirebaseDynamicLinks/Sources/Public/FirebaseDynamicLinks/FIRDynamicLinksCommon.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** A definition for a block used by methods that are asynchronous and may produce errors. */
  20. typedef void (^FIRDynamicLinkNetworkingErrorHandler)(NSError *_Nullable error);
  21. /** A definition for a block used to return a pending Dynamic Link. */
  22. typedef void (^FIRPostInstallAttributionCompletionHandler)(
  23. NSDictionary *_Nullable dynamicLinkParameters,
  24. NSString *_Nullable matchMessage,
  25. NSError *_Nullable error);
  26. /** A definition for a block used to return data and errors after an asynchronous task. */
  27. typedef void (^FIRNetworkRequestCompletionHandler)(NSData *_Nullable data,
  28. NSError *_Nullable error);
  29. // these enums must be in sync with google/firebase/dynamiclinks/v1/dynamic_links.proto
  30. typedef NS_ENUM(NSInteger, FIRDynamicLinkNetworkingUniqueMatchVisualStyle) {
  31. // Unknown style.
  32. FIRDynamicLinkNetworkingUniqueMatchVisualStyleUnknown = 0,
  33. // Default style.
  34. FIRDynamicLinkNetworkingUniqueMatchVisualStyleDefault = 1,
  35. // Custom style.
  36. FIRDynamicLinkNetworkingUniqueMatchVisualStyleCustom = 2,
  37. };
  38. typedef NS_ENUM(NSInteger, FIRDynamicLinkNetworkingRetrievalProcessType) {
  39. // Unknown method.
  40. FIRDynamicLinkNetworkingRetrievalProcessTypeUnknown = 0,
  41. // iSDK performs a server lookup using default match in the background
  42. // when app is first-opened; no API called by developer.
  43. FIRDynamicLinkNetworkingRetrievalProcessTypeImplicitDefault = 1,
  44. // iSDK performs a server lookup by device fingerprint upon a dev API call.
  45. FIRDynamicLinkNetworkingRetrievalProcessTypeExplicitDefault = 2,
  46. // iSDK performs a unique match only if default match is found upon a dev
  47. // API call.
  48. FIRDynamicLinkNetworkingRetrievalProcessTypeOptionalUnique = 3,
  49. };
  50. /**
  51. * @fn FIRMakeHTTPRequest
  52. * @abstract A basic and simple network request method.
  53. * @param request The NSURLRequest with which to perform the network request.
  54. * @param completion The handler executed after the request has completed.
  55. */
  56. void FIRMakeHTTPRequest(NSURLRequest *request, FIRNetworkRequestCompletionHandler completion);
  57. /** The base of the FDL API URL */
  58. FOUNDATION_EXPORT NSString *const kApiaryRestBaseUrl;
  59. /**
  60. * @class FIRDynamicLinkNetworking
  61. * @abstract The class used to handle all network communications for the the service.
  62. */
  63. @interface FIRDynamicLinkNetworking : NSObject
  64. /**
  65. * @method initWithAPIKey:URLScheme:
  66. * @param URLScheme Custom URL scheme of the app.
  67. * @param APIKey API Key value.
  68. */
  69. - (instancetype)initWithAPIKey:(NSString *)APIKey
  70. URLScheme:(NSString *)URLScheme NS_DESIGNATED_INITIALIZER;
  71. - (instancetype)init NS_UNAVAILABLE;
  72. /**
  73. * @method resolveShortLink:URLScheme:APIKey:completion:
  74. * @abstract Retrieves the details of the durable link that the shortened URL represents
  75. * @param url A Short Dynamic Link.
  76. * @param completion Block to be run upon completion.
  77. */
  78. - (void)resolveShortLink:(NSURL *)url
  79. FDLSDKVersion:(NSString *)FDLSDKVersion
  80. completion:(FIRDynamicLinkResolverHandler)completion;
  81. /**
  82. * @method
  83. * retrievePendingDynamicLinkWithIOSVersion:resolutionHeight:resolutionWidth:locale:localeRaw:timezone:modelName:FDLSDKVersion:appInstallationDate:uniqueMatchVisualStyle:retrievalProcessType:handler:
  84. * @abstract Retrieves a pending link from the server using the supplied device info and returns it
  85. * by executing the completion handler.
  86. */
  87. - (void)retrievePendingDynamicLinkWithIOSVersion:(NSString *)IOSVersion
  88. resolutionHeight:(NSInteger)resolutionHeight
  89. resolutionWidth:(NSInteger)resolutionWidth
  90. locale:(NSString *)locale
  91. localeRaw:(NSString *)localeRaw
  92. localeFromWebView:(NSString *)localeFromWebView
  93. timezone:(NSString *)timezone
  94. modelName:(NSString *)modelName
  95. FDLSDKVersion:(NSString *)FDLSDKVersion
  96. appInstallationDate:(NSDate *_Nullable)appInstallationDate
  97. uniqueMatchVisualStyle:
  98. (FIRDynamicLinkNetworkingUniqueMatchVisualStyle)uniqueMatchVisualStyle
  99. retrievalProcessType:
  100. (FIRDynamicLinkNetworkingRetrievalProcessType)retrievalProcessType
  101. uniqueMatchLinkToCheck:(NSURL *)uniqueMatchLinkToCheck
  102. handler:
  103. (FIRPostInstallAttributionCompletionHandler)handler;
  104. /**
  105. * @method convertInvitation:handler:
  106. * @abstract Marks an invitation as converted. You should call this method in your application after
  107. * the user performs an action that represents a successful conversion.
  108. * @param invitationID The invitation ID of the link.
  109. * @param handler A block that is called upon completion. If successful, the error parameter will be
  110. * nil. This is always executed on the main thread.
  111. */
  112. - (void)convertInvitation:(NSString *)invitationID
  113. handler:(nullable FIRDynamicLinkNetworkingErrorHandler)handler;
  114. @end
  115. NS_ASSUME_NONNULL_END