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