FIRInstallations.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 `FIRInstallationIDDidChangeNotification`. */
  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_NAME(InstallationsIDHandler);
  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_NAME(InstallationsTokenHandler);
  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)
  54. @interface FIRInstallations : NSObject
  55. - (instancetype)init NS_UNAVAILABLE;
  56. /**
  57. * Returns a default instance of `Installations`.
  58. * @returns An instance of `Installations` for `FirebaseApp.defaultApp().
  59. * @throw Throws an exception if the default app is not configured yet or required `FirebaseApp`
  60. * options are missing.
  61. */
  62. + (FIRInstallations *)installations NS_SWIFT_NAME(installations());
  63. /**
  64. * Returns an instance of `Installations` for an application.
  65. * @param application A configured `FirebaseApp` instance.
  66. * @returns An instance of `Installations` corresponding to the passed application.
  67. * @throw Throws an exception if required `FirebaseApp` options are missing.
  68. */
  69. + (FIRInstallations *)installationsWithApp:(FIRApp *)application
  70. NS_SWIFT_NAME(installations(app:));
  71. /**
  72. * The method creates or retrieves an installation ID. The installation ID is a stable identifier
  73. * that uniquely identifies the app instance. NOTE: If the application already has an existing
  74. * FirebaseInstanceID then the InstanceID identifier will be used.
  75. * @param completion A completion handler which is invoked when the operation completes. See
  76. * `InstallationsIDHandler` for additional details.
  77. */
  78. - (void)installationIDWithCompletion:(FIRInstallationsIDHandler)completion;
  79. /**
  80. * Retrieves (locally if it exists or from the server) a valid installation auth token. An existing
  81. * token may be invalidated or expired, so it is recommended to fetch the installation auth token
  82. * before each server request. The method does the same as `Installations.authTokenForcingRefresh(:,
  83. * completion:)` with forcing refresh `NO`.
  84. * @param completion A completion handler which is invoked when the operation completes. See
  85. * `InstallationsTokenHandler` for additional details.
  86. */
  87. - (void)authTokenWithCompletion:(FIRInstallationsTokenHandler)completion;
  88. /**
  89. * Retrieves (locally or from the server depending on `forceRefresh` value) a valid installation
  90. * auth token. An existing token may be invalidated or expire, so it is recommended to fetch the
  91. * installation auth token before each server request. This method should be used with `forceRefresh
  92. * == YES` when e.g. a request with the previously fetched installation auth token failed with "Not
  93. * Authorized" error.
  94. * @param forceRefresh If `YES` then the locally cached installation auth token will be ignored and
  95. * a new one will be requested from the server. If `NO`, then the locally cached installation auth
  96. * token will be returned if exists and has not expired yet.
  97. * @param completion A completion handler which is invoked when the operation completes. See
  98. * `InstallationsTokenHandler` for additional details.
  99. */
  100. - (void)authTokenForcingRefresh:(BOOL)forceRefresh
  101. completion:(FIRInstallationsTokenHandler)completion;
  102. /**
  103. * Deletes all the installation data including the unique identifier, auth tokens and
  104. * all related data on the server side. A network connection is required for the method to
  105. * succeed. If fails, the existing installation data remains untouched.
  106. * @param completion A completion handler which is invoked when the operation completes. `error ==
  107. * nil` indicates success.
  108. */
  109. - (void)deleteWithCompletion:(void (^)(NSError *__nullable error))completion;
  110. @end
  111. NS_ASSUME_NONNULL_END