From 17dfff1ed45eec57eb13c811a3a134f4dbf793df Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Thu, 7 Nov 2024 07:53:11 +0000 Subject: [PATCH] fix(messaging, ios): remove dummy APNS token for simulator (#13570) * fix(messaging, ios): remove fake APNS token for simulator * test(messaging): rm obsolete test --- .../ios/Classes/FLTFirebaseMessagingPlugin.m | 19 ------------------- .../firebase_messaging_e2e_test.dart | 7 ------- 2 files changed, 26 deletions(-) diff --git a/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m b/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m index 4a80cfd1a537..00c7400a3680 100644 --- a/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m +++ b/packages/firebase_messaging/firebase_messaging/ios/Classes/FLTFirebaseMessagingPlugin.m @@ -26,7 +26,6 @@ @implementation FLTFirebaseMessagingPlugin { NSObject *_registrar; NSData *_apnsToken; NSDictionary *_initialNotification; - bool simulatorToken; // Used to track if everything as been initialized before answering // to the initialNotification request @@ -57,7 +56,6 @@ - (instancetype)initWithFlutterMethodChannel:(FlutterMethodChannel *)channel _initialNotificationGathered = NO; _channel = channel; _registrar = registrar; - simulatorToken = false; // Application // Dart -> `getInitialNotification` // ObjC -> Initialize other delegates & observers @@ -1005,29 +1003,12 @@ + (NSDictionary *)remoteMessageUserInfoToDict:(NSDictionary *)userInfo { - (void)ensureAPNSTokenSetting { FIRMessaging *messaging = [FIRMessaging messaging]; - // With iOS SDK >= 10.4, an APNS token is required for getting/deleting token. We set a dummy - // token for the simulator for test environments. Historically, a simulator will not work for - // messaging. It will work if environment: iOS 16, running on macOS 13+ & silicon chip. We check - // the `_apnsToken` is nil. If it is, then the environment does not support and we set dummy - // token. -#if TARGET_IPHONE_SIMULATOR - if (simulatorToken == false && _apnsToken == nil) { - NSString *str = @"fake-apns-token-for-simulator"; - NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding]; - [[FIRMessaging messaging] setAPNSToken:data type:FIRMessagingAPNSTokenTypeSandbox]; - } - // We set this either way. We set dummy token once as `_apnsToken` could be nil next time - // which could possibly set dummy token unnecessarily - simulatorToken = true; -#endif - if (messaging.APNSToken == nil && _apnsToken != nil) { #ifdef DEBUG [[FIRMessaging messaging] setAPNSToken:_apnsToken type:FIRMessagingAPNSTokenTypeSandbox]; #else [[FIRMessaging messaging] setAPNSToken:_apnsToken type:FIRMessagingAPNSTokenTypeProd]; #endif - _apnsToken = nil; } } diff --git a/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart b/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart index 0db22fb77531..28e92985ba04 100644 --- a/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart +++ b/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart @@ -124,13 +124,6 @@ void main() { skip: defaultTargetPlatform != TargetPlatform.android, ); - test( - 'resolves dummy APNS token on ios if using simulator', - () async { - expect(await messaging.getAPNSToken(), isA()); - }, - skip: defaultTargetPlatform != TargetPlatform.iOS, - ); }); group('getInitialMessage', () {