You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
11 KiB

6 years ago
  1. #import <Foundation/Foundation.h>
  2. /**
  3. * @memberof FIRInstanceID
  4. *
  5. * The scope to be used when fetching/deleting a token for Firebase Messaging.
  6. */
  7. FOUNDATION_EXPORT NSString *__nonnull const kFIRInstanceIDScopeFirebaseMessaging
  8. NS_SWIFT_NAME(InstanceIDScopeFirebaseMessaging);
  9. #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  10. /**
  11. * Called when the system determines that tokens need to be refreshed.
  12. * This method is also called if Instance ID has been reset in which
  13. * case, tokens and FCM topic subscriptions also need to be refreshed.
  14. *
  15. * Instance ID service will throttle the refresh event across all devices
  16. * to control the rate of token updates on application servers.
  17. */
  18. FOUNDATION_EXPORT const NSNotificationName __nonnull kFIRInstanceIDTokenRefreshNotification
  19. NS_SWIFT_NAME(InstanceIDTokenRefresh);
  20. #else
  21. /**
  22. * Called when the system determines that tokens need to be refreshed.
  23. * This method is also called if Instance ID has been reset in which
  24. * case, tokens and FCM topic subscriptions also need to be refreshed.
  25. *
  26. * Instance ID service will throttle the refresh event across all devices
  27. * to control the rate of token updates on application servers.
  28. */
  29. FOUNDATION_EXPORT NSString *__nonnull const kFIRInstanceIDTokenRefreshNotification
  30. NS_SWIFT_NAME(InstanceIDTokenRefreshNotification);
  31. #endif // defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  32. /**
  33. * @related FIRInstanceID
  34. *
  35. * The completion handler invoked when the InstanceID token returns. If
  36. * the call fails we return the appropriate `error code` as described below.
  37. *
  38. * @param token The valid token as returned by InstanceID backend.
  39. *
  40. * @param error The error describing why generating a new token
  41. * failed. See the error codes below for a more detailed
  42. * description.
  43. */
  44. typedef void (^FIRInstanceIDTokenHandler)(NSString *__nullable token, NSError *__nullable error)
  45. NS_SWIFT_NAME(InstanceIDTokenHandler);
  46. /**
  47. * @related FIRInstanceID
  48. *
  49. * The completion handler invoked when the InstanceID `deleteToken` returns. If
  50. * the call fails we return the appropriate `error code` as described below
  51. *
  52. * @param error The error describing why deleting the token failed.
  53. * See the error codes below for a more detailed description.
  54. */
  55. typedef void (^FIRInstanceIDDeleteTokenHandler)(NSError *__nullable error)
  56. NS_SWIFT_NAME(InstanceIDDeleteTokenHandler);
  57. /**
  58. * @related FIRInstanceID
  59. *
  60. * The completion handler invoked when the app identity is created. If the
  61. * identity wasn't created for some reason we return the appropriate error code.
  62. *
  63. * @param identity A valid identity for the app instance, nil if there was an error
  64. * while creating an identity.
  65. * @param error The error if fetching the identity fails else nil.
  66. */
  67. typedef void (^FIRInstanceIDHandler)(NSString *__nullable identity, NSError *__nullable error)
  68. NS_SWIFT_NAME(InstanceIDHandler);
  69. /**
  70. * @related FIRInstanceID
  71. *
  72. * The completion handler invoked when the app identity and all the tokens associated
  73. * with it are deleted. Returns a valid error object in case of failure else nil.
  74. *
  75. * @param error The error if deleting the identity and all the tokens associated with
  76. * it fails else nil.
  77. */
  78. typedef void (^FIRInstanceIDDeleteHandler)(NSError *__nullable error)
  79. NS_SWIFT_NAME(InstanceIDDeleteHandler);
  80. /**
  81. * Public errors produced by InstanceID.
  82. */
  83. typedef NS_ENUM(NSUInteger, FIRInstanceIDError) {
  84. // Http related errors.
  85. /// Unknown error.
  86. FIRInstanceIDErrorUnknown = 0,
  87. /// Auth Error -- GCM couldn't validate request from this client.
  88. FIRInstanceIDErrorAuthentication = 1,
  89. /// NoAccess -- InstanceID service cannot be accessed.
  90. FIRInstanceIDErrorNoAccess = 2,
  91. /// Timeout -- Request to InstanceID backend timed out.
  92. FIRInstanceIDErrorTimeout = 3,
  93. /// Network -- No network available to reach the servers.
  94. FIRInstanceIDErrorNetwork = 4,
  95. /// OperationInProgress -- Another similar operation in progress,
  96. /// bailing this one.
  97. FIRInstanceIDErrorOperationInProgress = 5,
  98. /// InvalidRequest -- Some parameters of the request were invalid.
  99. FIRInstanceIDErrorInvalidRequest = 7,
  100. } NS_SWIFT_NAME(InstanceIDError);
  101. /**
  102. * Instance ID provides a unique identifier for each app instance and a mechanism
  103. * to authenticate and authorize actions (for example, sending an FCM message).
  104. *
  105. * Once an InstanceID is generated, the library periodically sends information about the
  106. * application and the device where it's running to the Firebase backend. To stop this. see
  107. * `[FIRInstanceID deleteIDWithHandler:]`.
  108. *
  109. * Instance ID is long lived but, may be reset if the device is not used for
  110. * a long time or the Instance ID service detects a problem.
  111. * If Instance ID is reset, the app will be notified via
  112. * `kFIRInstanceIDTokenRefreshNotification`.
  113. *
  114. * If the Instance ID has become invalid, the app can request a new one and
  115. * send it to the app server.
  116. * To prove ownership of Instance ID and to allow servers to access data or
  117. * services associated with the app, call
  118. * `[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]`.
  119. */
  120. NS_SWIFT_NAME(InstanceID)
  121. @interface FIRInstanceID : NSObject
  122. /**
  123. * FIRInstanceID.
  124. *
  125. * @return A shared instance of FIRInstanceID.
  126. */
  127. + (nonnull instancetype)instanceID NS_SWIFT_NAME(instanceID());
  128. /**
  129. * Unavailable. Use +instanceID instead.
  130. */
  131. - (nonnull instancetype)init __attribute__((unavailable("Use +instanceID instead.")));
  132. #pragma mark - Tokens
  133. /**
  134. * Returns a Firebase Messaging scoped token for the firebase app.
  135. *
  136. * @return Returns the stored token if the device has registered with Firebase Messaging, otherwise
  137. * returns nil.
  138. */
  139. - (nullable NSString *)token;
  140. /**
  141. * Returns a token that authorizes an Entity (example: cloud service) to perform
  142. * an action on behalf of the application identified by Instance ID.
  143. *
  144. * This is similar to an OAuth2 token except, it applies to the
  145. * application instance instead of a user.
  146. *
  147. * This is an asynchronous call. If the token fetching fails for some reason
  148. * we invoke the completion callback with nil `token` and the appropriate
  149. * error.
  150. *
  151. * This generates an Instance ID if it does not exist yet, which starts periodically sending
  152. * information to the Firebase backend (see `[FIRInstanceID getIDWithHandler:]`).
  153. *
  154. * Note, you can only have one `token` or `deleteToken` call for a given
  155. * authorizedEntity and scope at any point of time. Making another such call with the
  156. * same authorizedEntity and scope before the last one finishes will result in an
  157. * error with code `OperationInProgress`.
  158. *
  159. * @see FIRInstanceID deleteTokenWithAuthorizedEntity:scope:handler:
  160. *
  161. * @param authorizedEntity Entity authorized by the token.
  162. * @param scope Action authorized for authorizedEntity.
  163. * @param options The extra options to be sent with your token request. The
  164. * value for the `apns_token` should be the NSData object
  165. * passed to the UIApplicationDelegate's
  166. * `didRegisterForRemoteNotificationsWithDeviceToken` method.
  167. * The value for `apns_sandbox` should be a boolean (or an
  168. * NSNumber representing a BOOL in Objective C) set to true if
  169. * your app is a debug build, which means that the APNs
  170. * device token is for the sandbox environment. It should be
  171. * set to false otherwise. If the `apns_sandbox` key is not
  172. * provided, an automatically-detected value shall be used.
  173. * @param handler The callback handler which is invoked when the token is
  174. * successfully fetched. In case of success a valid `token` and
  175. * `nil` error are returned. In case of any error the `token`
  176. * is nil and a valid `error` is returned. The valid error
  177. * codes have been documented above.
  178. */
  179. - (void)tokenWithAuthorizedEntity:(nonnull NSString *)authorizedEntity
  180. scope:(nonnull NSString *)scope
  181. options:(nullable NSDictionary *)options
  182. handler:(nonnull FIRInstanceIDTokenHandler)handler;
  183. /**
  184. * Revokes access to a scope (action) for an entity previously
  185. * authorized by `[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]`.
  186. *
  187. * This is an asynchronous call. Call this on the main thread since InstanceID lib
  188. * is not thread safe. In case token deletion fails for some reason we invoke the
  189. * `handler` callback passed in with the appropriate error code.
  190. *
  191. * Note, you can only have one `token` or `deleteToken` call for a given
  192. * authorizedEntity and scope at a point of time. Making another such call with the
  193. * same authorizedEntity and scope before the last one finishes will result in an error
  194. * with code `OperationInProgress`.
  195. *
  196. * @param authorizedEntity Entity that must no longer have access.
  197. * @param scope Action that entity is no longer authorized to perform.
  198. * @param handler The handler that is invoked once the unsubscribe call ends.
  199. * In case of error an appropriate error object is returned
  200. * else error is nil.
  201. */
  202. - (void)deleteTokenWithAuthorizedEntity:(nonnull NSString *)authorizedEntity
  203. scope:(nonnull NSString *)scope
  204. handler:(nonnull FIRInstanceIDDeleteTokenHandler)handler;
  205. #pragma mark - Identity
  206. /**
  207. * Asynchronously fetch a stable identifier that uniquely identifies the app
  208. * instance. If the identifier has been revoked or has expired, this method will
  209. * return a new identifier.
  210. *
  211. * Once an InstanceID is generated, the library periodically sends information about the
  212. * application and the device where it's running to the Firebase backend. To stop this. see
  213. * `[FIRInstanceID deleteIDWithHandler:]`.
  214. *
  215. * @param handler The handler to invoke once the identifier has been fetched.
  216. * In case of error an appropriate error object is returned else
  217. * a valid identifier is returned and a valid identifier for the
  218. * application instance.
  219. */
  220. - (void)getIDWithHandler:(nonnull FIRInstanceIDHandler)handler NS_SWIFT_NAME(getID(handler:));
  221. /**
  222. * Resets Instance ID and revokes all tokens.
  223. *
  224. * This method also triggers a request to fetch a new Instance ID and Firebase Messaging scope
  225. * token. Please listen to kFIRInstanceIDTokenRefreshNotification when the new ID and token are
  226. * ready.
  227. *
  228. * This stops the periodic sending of data to the Firebase backend that began when the Instance ID
  229. * was generated. No more data is sent until another library calls Instance ID internally again
  230. * (like FCM, RemoteConfig or Analytics) or user explicitly calls Instance ID APIs to get an
  231. * Instance ID and token again.
  232. */
  233. - (void)deleteIDWithHandler:(nonnull FIRInstanceIDDeleteHandler)handler
  234. NS_SWIFT_NAME(deleteID(handler:));
  235. @end