Skip to content

Commit

Permalink
Merge branch 'main' into auth-13567
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Nov 7, 2024
2 parents c7bf510 + 17dfff1 commit ee58917
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ @implementation FLTFirebaseMessagingPlugin {
NSObject<FlutterPluginRegistrar> *_registrar;
NSData *_apnsToken;
NSDictionary *_initialNotification;
bool simulatorToken;

// Used to track if everything as been initialized before answering
// to the initialNotification request
Expand Down Expand Up @@ -57,7 +56,6 @@ - (instancetype)initWithFlutterMethodChannel:(FlutterMethodChannel *)channel
_initialNotificationGathered = NO;
_channel = channel;
_registrar = registrar;
simulatorToken = false;
// Application
// Dart -> `getInitialNotification`
// ObjC -> Initialize other delegates & observers
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:tests/firebase_options.dart';

// ignore: do_not_use_environment
const bool skipTestsOnCI = bool.fromEnvironment('CI');

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -40,6 +43,7 @@ void main() {
expect(result, isA<int?>());
}
},
skip: skipTestsOnCI && defaultTargetPlatform == TargetPlatform.iOS,
);

test('isSupported', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>());
},
skip: defaultTargetPlatform != TargetPlatform.iOS,
);
});

group('getInitialMessage', () {
Expand Down Expand Up @@ -178,9 +171,8 @@ void main() {
},
// macOS skipped because it needs keychain sharing entitlement. See: https://github.com/firebase/flutterfire/issues/9538
// android skipped due to consistently failing, works locally: https://github.com/firebase/flutterfire/pull/11260
skip: kIsWeb ||
defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.android,
// iOS fails because APNS token handler doesn't have a chance to receive token before calling this method
skip: kIsWeb || skipTestsOnCI,
);
});

Expand All @@ -193,9 +185,8 @@ void main() {
},
// macOS skipped because it needs keychain sharing entitlement. See: https://github.com/firebase/flutterfire/issues/9538
// android skipped due to consistently failing, works locally: https://github.com/firebase/flutterfire/pull/11260
skip: kIsWeb ||
defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.android,
// iOS fails because APNS token handler doesn't have a chance to receive token before calling this method
skip: kIsWeb || skipTestsOnCI,
);
});

Expand Down

0 comments on commit ee58917

Please sign in to comment.