Skip to content

Commit 0b7fc7e

Browse files
Xcode 14 - support push notifications in iOS simulator (#10503)
* Xcode 14 - support push notifications in iOS simulator * style fixes * Refactor 'type' variable closer to usage * Added CHANGELOG entry * Added fix number (ID) to CHANGELOG
1 parent 82a242f commit 0b7fc7e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

FirebaseMessaging/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 10.3.0
2+
- [changed] Allow notification support on iOS 16 Simulator on Xcode 14 (#9968) (Reference: Xcode 14 Release Notes -> Simulator -> New Features: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes)
3+
14
# 10.1.0
25
- [fixed] App bundle identifier gets incorrectly shortened for watchOS apps created on Xcode 14 (#10147)
36

FirebaseMessaging/Sources/Token/FIRMessagingTokenManager.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ - (void)tokenWithAuthorizedEntity:(NSString *)authorizedEntity
180180
[tokenOptions addEntriesFromDictionary:options];
181181
}
182182

183+
#if TARGET_OS_SIMULATOR && TARGET_OS_IOS
184+
if (tokenOptions[kFIRMessagingTokenOptionsAPNSKey] != nil) {
185+
// If APNS token is available on iOS Simulator, we must use the sandbox profile
186+
// https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
187+
tokenOptions[kFIRMessagingTokenOptionsAPNSIsSandboxKey] = @(YES);
188+
}
189+
#endif
190+
183191
if (tokenOptions[kFIRMessagingTokenOptionsAPNSKey] != nil &&
184192
tokenOptions[kFIRMessagingTokenOptionsAPNSIsSandboxKey] == nil) {
185193
// APNS key was given, but server type is missing. Supply the server type with automatic
@@ -634,7 +642,6 @@ - (void)setAPNSToken:(NSData *)APNSToken withUserInfo:(NSDictionary *)userInfo {
634642
}
635643
return;
636644
}
637-
NSInteger type = [userInfo[kFIRMessagingAPNSTokenType] integerValue];
638645

639646
// The APNS token is being added, or has changed (rare)
640647
if ([self.currentAPNSInfo.deviceToken isEqualToData:APNSToken]) {
@@ -643,10 +650,17 @@ - (void)setAPNSToken:(NSData *)APNSToken withUserInfo:(NSDictionary *)userInfo {
643650
return;
644651
}
645652
// Use this token type for when we have to automatically fetch tokens in the future
653+
#if TARGET_OS_SIMULATOR && TARGET_OS_IOS
654+
// If APNS token is available on iOS Simulator, we must use the sandbox profile
655+
// https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
656+
BOOL isSandboxApp = YES;
657+
#else
658+
NSInteger type = [userInfo[kFIRMessagingAPNSTokenType] integerValue];
646659
BOOL isSandboxApp = (type == FIRMessagingAPNSTokenTypeSandbox);
647660
if (type == FIRMessagingAPNSTokenTypeUnknown) {
648661
isSandboxApp = FIRMessagingIsSandboxApp();
649662
}
663+
#endif
650664

651665
// Pro-actively invalidate the default token, if the APNs change makes it
652666
// invalid. Previously, we invalidated just before fetching the token.

0 commit comments

Comments
 (0)