added iOS source code
[wl-app.git] / iOS / Pods / FirebaseCore / Firebase / Core / Private / FIRAppInternal.h
1 /*
2  * Copyright 2017 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 "FIRApp.h"
18 #import "FIRErrors.h"
19
20 @class FIRComponentContainer;
21 @protocol FIRCoreConfigurable;
22
23 /**
24  * The internal interface to FIRApp. This is meant for first-party integrators, who need to receive
25  * FIRApp notifications, log info about the success or failure of their configuration, and access
26  * other internal functionality of FIRApp.
27  *
28  * TODO(b/28296561): Restructure this header.
29  */
30 NS_ASSUME_NONNULL_BEGIN
31
32 typedef NS_ENUM(NSInteger, FIRConfigType) {
33   FIRConfigTypeCore = 1,
34   FIRConfigTypeSDK = 2,
35 };
36
37 /**
38  * Names of services provided by Firebase.
39  */
40 extern NSString *const kFIRServiceAdMob;
41 extern NSString *const kFIRServiceAuth;
42 extern NSString *const kFIRServiceAuthUI;
43 extern NSString *const kFIRServiceCrash;
44 extern NSString *const kFIRServiceDatabase;
45 extern NSString *const kFIRServiceDynamicLinks;
46 extern NSString *const kFIRServiceInstanceID;
47 extern NSString *const kFIRServiceInvites;
48 extern NSString *const kFIRServiceMessaging;
49 extern NSString *const kFIRServiceMeasurement;
50 extern NSString *const kFIRServiceRemoteConfig;
51 extern NSString *const kFIRServiceStorage;
52
53 /**
54  * Names of services provided by the Google pod, but logged by the Firebase pod.
55  */
56 extern NSString *const kGGLServiceAnalytics;
57 extern NSString *const kGGLServiceSignIn;
58
59 extern NSString *const kFIRDefaultAppName;
60 extern NSString *const kFIRAppReadyToConfigureSDKNotification;
61 extern NSString *const kFIRAppDeleteNotification;
62 extern NSString *const kFIRAppIsDefaultAppKey;
63 extern NSString *const kFIRAppNameKey;
64 extern NSString *const kFIRGoogleAppIDKey;
65
66 /**
67  * The format string for the User Defaults key used for storing the data collection enabled flag.
68  * This includes formatting to append the Firebase App's name.
69  */
70 extern NSString *const kFIRGlobalAppDataCollectionEnabledDefaultsKeyFormat;
71
72 /**
73  * The plist key used for storing the data collection enabled flag.
74  */
75 extern NSString *const kFIRGlobalAppDataCollectionEnabledPlistKey;
76
77 /**
78  * A notification fired containing diagnostic information when SDK errors occur.
79  */
80 extern NSString *const kFIRAppDiagnosticsNotification;
81
82 /** @var FIRAuthStateDidChangeInternalNotification
83  @brief The name of the @c NSNotificationCenter notification which is posted when the auth state
84  changes (e.g. a new token has been produced, a user logs in or out). The object parameter of
85  the notification is a dictionary possibly containing the key:
86  @c FIRAuthStateDidChangeInternalNotificationTokenKey (the new access token.) If it does not
87  contain this key it indicates a sign-out event took place.
88  */
89 extern NSString *const FIRAuthStateDidChangeInternalNotification;
90
91 /** @var FIRAuthStateDidChangeInternalNotificationTokenKey
92  @brief A key present in the dictionary object parameter of the
93  @c FIRAuthStateDidChangeInternalNotification notification. The value associated with this
94  key will contain the new access token.
95  */
96 extern NSString *const FIRAuthStateDidChangeInternalNotificationTokenKey;
97
98 /** @var FIRAuthStateDidChangeInternalNotificationAppKey
99  @brief A key present in the dictionary object parameter of the
100  @c FIRAuthStateDidChangeInternalNotification notification. The value associated with this
101  key will contain the FIRApp associated with the auth instance.
102  */
103 extern NSString *const FIRAuthStateDidChangeInternalNotificationAppKey;
104
105 /** @var FIRAuthStateDidChangeInternalNotificationUIDKey
106  @brief A key present in the dictionary object parameter of the
107  @c FIRAuthStateDidChangeInternalNotification notification. The value associated with this
108  key will contain the new user's UID (or nil if there is no longer a user signed in).
109  */
110 extern NSString *const FIRAuthStateDidChangeInternalNotificationUIDKey;
111
112 /** @typedef FIRTokenCallback
113     @brief The type of block which gets called when a token is ready.
114  */
115 typedef void (^FIRTokenCallback)(NSString *_Nullable token, NSError *_Nullable error);
116
117 /** @typedef FIRAppGetTokenImplementation
118     @brief The type of block which can provide an implementation for the @c getTokenWithCallback:
119         method.
120     @param forceRefresh Forces the token to be refreshed.
121     @param callback The block which should be invoked when the async call completes.
122  */
123 typedef void (^FIRAppGetTokenImplementation)(BOOL forceRefresh, FIRTokenCallback callback);
124
125 /** @typedef FIRAppGetUID
126     @brief The type of block which can provide an implementation for the @c getUID method.
127  */
128 typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void);
129
130 @interface FIRApp ()
131
132 /**
133  * A flag indicating if this is the default app.
134  */
135 @property(nonatomic, readonly) BOOL isDefaultApp;
136
137 /** @property getTokenImplementation
138     @brief Gets or sets the block to use for the implementation of
139         @c getTokenForcingRefresh:withCallback:
140  */
141 @property(nonatomic, copy) FIRAppGetTokenImplementation getTokenImplementation;
142
143 /** @property getUIDImplementation
144     @brief Gets or sets the block to use for the implementation of @c getUID.
145  */
146 @property(nonatomic, copy) FIRAppGetUIDImplementation getUIDImplementation;
147
148 /*
149  * The container of interop SDKs for this app.
150  */
151 @property(nonatomic) FIRComponentContainer *container;
152
153 /**
154  * Creates an error for failing to configure a subspec service. This method is called by each
155  * FIRApp notification listener.
156  */
157 + (NSError *)errorForSubspecConfigurationFailureWithDomain:(NSString *)domain
158                                                  errorCode:(FIRErrorCode)code
159                                                    service:(NSString *)service
160                                                     reason:(NSString *)reason;
161 /**
162  * Checks if the default app is configured without trying to configure it.
163  */
164 + (BOOL)isDefaultAppConfigured;
165
166 /**
167  * Register a class that conforms to `FIRCoreConfigurable`. Each SDK should have one class that
168  * registers in order to provide critical information for interoperability and lifecycle events.
169  * TODO(wilsonryan): Write more documentation.
170  */
171 + (void)registerAsConfigurable:(Class<FIRCoreConfigurable>)klass;
172
173 /**
174  * Registers a given third-party library with the given version number to be reported for
175  * analyitcs.
176  *
177  * @param library Name of the library
178  * @param version Version of the library
179  */
180 // clang-format off
181 + (void)registerLibrary:(NSString *)library
182             withVersion:(NSString *)version NS_SWIFT_NAME(registerLibrary(_:version:));
183 // clang-format on
184
185 /**
186  * A concatenated string representing all the third-party libraries and version numbers.
187  */
188 + (NSString *)firebaseUserAgent;
189
190 /**
191  * Used by each SDK to send logs about SDK configuration status to Clearcut.
192  */
193 - (void)sendLogsWithServiceName:(NSString *)serviceName
194                         version:(NSString *)version
195                           error:(NSError *)error;
196
197 /**
198  * Can be used by the unit tests in eack SDK to reset FIRApp. This method is thread unsafe.
199  */
200 + (void)resetApps;
201
202 /**
203  * Can be used by the unit tests in each SDK to set customized options.
204  */
205 - (instancetype)initInstanceWithName:(NSString *)name options:(FIROptions *)options;
206
207 /** @fn getTokenForcingRefresh:withCallback:
208     @brief Retrieves the Firebase authentication token, possibly refreshing it.
209     @param forceRefresh Forces a token refresh. Useful if the token becomes invalid for some reason
210         other than an expiration.
211     @param callback The block to invoke when the token is available.
212  */
213 - (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(FIRTokenCallback)callback;
214
215 /**
216  * Expose the UID of the current user for Firestore.
217  */
218 - (nullable NSString *)getUID;
219
220 @end
221
222 NS_ASSUME_NONNULL_END