FIRInstallations.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright 2019 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. @class FIRApp;
  18. @class FIRInstallationsAuthTokenResult;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /** A notification with this name is sent each time an installation is created or deleted. */
  21. FOUNDATION_EXPORT const NSNotificationName FIRInstallationIDDidChangeNotification;
  22. /** `userInfo` key for the `FirebaseApp.name` in `FIRInstallationIDDidChangeNotification`. */
  23. FOUNDATION_EXPORT NSString *const kFIRInstallationIDDidChangeNotificationAppNameKey;
  24. /**
  25. * An installation ID handler block.
  26. * @param identifier The installation ID string if exists or `nil` otherwise.
  27. * @param error The error when `identifier == nil` or `nil` otherwise.
  28. */
  29. typedef void (^FIRInstallationsIDHandler)(NSString *__nullable identifier,
  30. NSError *__nullable error)
  31. NS_SWIFT_NAME(InstallationsIDHandler);
  32. /**
  33. * An authorization token handler block.
  34. * @param tokenResult An instance of `InstallationsAuthTokenResult` in case of success or `nil`
  35. * otherwise.
  36. * @param error The error when `tokenResult == nil` or `nil` otherwise.
  37. */
  38. typedef void (^FIRInstallationsTokenHandler)(
  39. FIRInstallationsAuthTokenResult *__nullable tokenResult, NSError *__nullable error)
  40. NS_SWIFT_NAME(InstallationsTokenHandler);
  41. /**
  42. * The class provides API for Firebase Installations.
  43. * Each configured `FirebaseApp` has a corresponding single instance of `Installations`.
  44. * An instance of the class provides access to the installation info for the `FirebaseApp` as well
  45. * as the ability to delete it. A Firebase Installation is unique by `FirebaseApp.name` and
  46. * `FirebaseApp.options.googleAppID` .
  47. */
  48. NS_SWIFT_NAME(Installations)
  49. @interface FIRInstallations : NSObject
  50. - (instancetype)init NS_UNAVAILABLE;
  51. /**
  52. * Returns a default instance of `Installations`.
  53. * @returns An instance of `Installations` for `FirebaseApp.defaultApp().
  54. * @throw Throws an exception if the default app is not configured yet or required `FirebaseApp`
  55. * options are missing.
  56. */
  57. + (FIRInstallations *)installations NS_SWIFT_NAME(installations());
  58. /**
  59. * Returns an instance of `Installations` for an application.
  60. * @param application A configured `FirebaseApp` instance.
  61. * @returns An instance of `Installations` corresponding to the passed application.
  62. * @throw Throws an exception if required `FirebaseApp` options are missing.
  63. */
  64. + (FIRInstallations *)installationsWithApp:(FIRApp *)application NS_SWIFT_NAME(installations(app:));
  65. /**
  66. * The method creates or retrieves an installation ID. The installation ID is a stable identifier
  67. * that uniquely identifies the app instance. NOTE: If the application already has an existing
  68. * FirebaseInstanceID then the InstanceID identifier will be used.
  69. * @param completion A completion handler which is invoked when the operation completes. See
  70. * `InstallationsIDHandler` for additional details.
  71. */
  72. - (void)installationIDWithCompletion:(FIRInstallationsIDHandler)completion;
  73. /**
  74. * Retrieves (locally if it exists or from the server) a valid authorization token. An existing
  75. * token may be invalidated or expired, so it is recommended to fetch the auth token before each
  76. * server request. The method does the same as `Installations.authTokenForcingRefresh(:,
  77. * completion:)` with forcing refresh `NO`.
  78. * @param completion A completion handler which is invoked when the operation completes. See
  79. * `InstallationsTokenHandler` for additional details.
  80. */
  81. - (void)authTokenWithCompletion:(FIRInstallationsTokenHandler)completion;
  82. /**
  83. * Retrieves (locally or from the server depending on `forceRefresh` value) a valid authorization
  84. * token. An existing token may be invalidated or expire, so it is recommended to fetch the auth
  85. * token before each server request. This method should be used with `forceRefresh == YES` when e.g.
  86. * a request with the previously fetched auth token failed with "Not Authorized" error.
  87. * @param forceRefresh If `YES` then the locally cached auth token will be ignored and a new one
  88. * will be requested from the server. If `NO`, then the locally cached auth token will be returned
  89. * if exists and has not expired yet.
  90. * @param completion A completion handler which is invoked when the operation completes. See
  91. * `InstallationsTokenHandler` for additional details.
  92. */
  93. - (void)authTokenForcingRefresh:(BOOL)forceRefresh
  94. completion:(FIRInstallationsTokenHandler)completion;
  95. /**
  96. * Deletes all the installation data including the unique identifier, auth tokens and
  97. * all related data on the server side. A network connection is required for the method to
  98. * succeed. If fails, the existing installation data remains untouched.
  99. * @param completion A completion handler which is invoked when the operation completes. `error ==
  100. * nil` indicates success.
  101. */
  102. - (void)deleteWithCompletion:(void (^)(NSError *__nullable error))completion;
  103. @end
  104. NS_ASSUME_NONNULL_END