Skip to content

Commit

Permalink
fix(firebase_auth): Update APN token once auth plugin has been initia…
Browse files Browse the repository at this point in the history
…lized on `iOS`. (#8201)

Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
  • Loading branch information
russellwheatley and Salakar committed Mar 15, 2022
1 parent 22bbd80 commit ab6239d
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ @implementation FLTFirebaseAuthPlugin {
NSObject<FlutterBinaryMessenger> *_binaryMessenger;
NSMutableDictionary<NSString *, FlutterEventChannel *> *_eventChannels;
NSMutableDictionary<NSString *, NSObject<FlutterStreamHandler> *> *_streamHandlers;
NSData *_apnsToken;
}

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

[self ensureAPNSTokenSetting];

if ([@"Auth#registerIdTokenListener" isEqualToString:call.method]) {
[self registerIdTokenListener:call.arguments withMethodCallResult:methodCallResult];
} else if ([@"Auth#registerAuthStateListener" isEqualToString:call.method]) {
Expand Down Expand Up @@ -242,7 +245,7 @@ - (BOOL)application:(UIApplication *)application

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[FIRAuth auth] setAPNSToken:deviceToken type:FIRAuthAPNSTokenTypeUnknown];
_apnsToken = deviceToken;
}

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

- (void)ensureAPNSTokenSetting {
#if !TARGET_OS_OSX
FIRApp *defaultApp = [FIRApp defaultApp];
if (defaultApp) {
if ([FIRAuth auth].APNSToken == nil && _apnsToken != nil) {
[[FIRAuth auth] setAPNSToken:_apnsToken type:FIRAuthAPNSTokenTypeUnknown];
_apnsToken = nil;
}
}
#endif
}

@end

0 comments on commit ab6239d

Please sign in to comment.