Skip to content

Commit ab6239d

Browse files
fix(firebase_auth): Update APN token once auth plugin has been initialized on iOS. (#8201)
Co-authored-by: Mike Diarmid <[email protected]>
1 parent 22bbd80 commit ab6239d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ @implementation FLTFirebaseAuthPlugin {
5959
NSObject<FlutterBinaryMessenger> *_binaryMessenger;
6060
NSMutableDictionary<NSString *, FlutterEventChannel *> *_eventChannels;
6161
NSMutableDictionary<NSString *, NSObject<FlutterStreamHandler> *> *_streamHandlers;
62+
NSData *_apnsToken;
6263
}
6364

6465
#pragma mark - FlutterPlugin
@@ -155,6 +156,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutter
155156
FLTFirebaseMethodCallResult *methodCallResult =
156157
[FLTFirebaseMethodCallResult createWithSuccess:successBlock andErrorBlock:errorBlock];
157158

159+
[self ensureAPNSTokenSetting];
160+
158161
if ([@"Auth#registerIdTokenListener" isEqualToString:call.method]) {
159162
[self registerIdTokenListener:call.arguments withMethodCallResult:methodCallResult];
160163
} else if ([@"Auth#registerAuthStateListener" isEqualToString:call.method]) {
@@ -242,7 +245,7 @@ - (BOOL)application:(UIApplication *)application
242245

243246
- (void)application:(UIApplication *)application
244247
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
245-
[[FIRAuth auth] setAPNSToken:deviceToken type:FIRAuthAPNSTokenTypeUnknown];
248+
_apnsToken = deviceToken;
246249
}
247250

248251
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
@@ -1285,4 +1288,16 @@ + (NSMutableDictionary *)getNSDictionaryFromUser:(FIRUser *)user {
12851288
return userData;
12861289
}
12871290

1291+
- (void)ensureAPNSTokenSetting {
1292+
#if !TARGET_OS_OSX
1293+
FIRApp *defaultApp = [FIRApp defaultApp];
1294+
if (defaultApp) {
1295+
if ([FIRAuth auth].APNSToken == nil && _apnsToken != nil) {
1296+
[[FIRAuth auth] setAPNSToken:_apnsToken type:FIRAuthAPNSTokenTypeUnknown];
1297+
_apnsToken = nil;
1298+
}
1299+
}
1300+
#endif
1301+
}
1302+
12881303
@end

0 commit comments

Comments
 (0)