FIRInstallations.h 5.9 KB

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