Skip to content

Commit 7ab2b94

Browse files
[Messaging] Xcode 14 watchkit extension bundle id fix (#10324)
* Xcode 14 watchkit extension bundle id fix * Fix unit test for new extension point identifier check * fix code style issue * updated CHANGELOG.md
1 parent 77e7b23 commit 7ab2b94

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
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.1.0
2+
- [fixed] App bundle identifier gets incorrectly shortened for watchOS apps created on Xcode 14 (#10147)
3+
14
# 8.12.0
25
- [changed] Improved reporting for SQLite errors when failing to open a local database (#8699).
36

FirebaseMessaging/Sources/FIRMessagingUtilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ FOUNDATION_EXPORT int64_t FIRMessagingCurrentTimestampInMilliseconds(void);
3030
FOUNDATION_EXPORT NSString *FIRMessagingCurrentAppVersion(void);
3131
FOUNDATION_EXPORT NSString *FIRMessagingAppIdentifier(void);
3232
FOUNDATION_EXPORT NSString *FIRMessagingFirebaseAppID(void);
33+
FOUNDATION_EXPORT BOOL FIRMessagingIsWatchKitExtension(void);
3334

3435
#pragma mark - Others
3536

FirebaseMessaging/Sources/FIRMessagingUtilities.m

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
static NSString *const kFIRMessagingAPNSSandboxPrefix = @"s_";
2828
static NSString *const kFIRMessagingAPNSProdPrefix = @"p_";
2929

30+
static NSString *const kFIRMessagingWatchKitExtensionPoint = @"com.apple.watchkit";
31+
3032
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
3133
static NSString *const kEntitlementsAPSEnvironmentKey = @"Entitlements.aps-environment";
3234
#else
@@ -76,10 +78,14 @@ int64_t FIRMessagingCurrentTimestampInMilliseconds(void) {
7678
NSString *FIRMessagingAppIdentifier(void) {
7779
NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
7880
#if TARGET_OS_WATCH
79-
// The code is running in watchKit extension target but the actually bundleID is in the watchKit
80-
// target. So we need to remove the last part of the bundle ID in watchKit extension to match
81-
// the one in watchKit target.
82-
return FIRMessagingBundleIDByRemovingLastPartFrom(bundleID);
81+
if (FIRMessagingIsWatchKitExtension()) {
82+
// The code is running in watchKit extension target but the actually bundleID is in the watchKit
83+
// target. So we need to remove the last part of the bundle ID in watchKit extension to match
84+
// the one in watchKit target.
85+
return FIRMessagingBundleIDByRemovingLastPartFrom(bundleID);
86+
} else {
87+
return bundleID;
88+
}
8389
#else
8490
return bundleID;
8591
#endif
@@ -89,6 +95,25 @@ int64_t FIRMessagingCurrentTimestampInMilliseconds(void) {
8995
return [FIROptions defaultOptions].googleAppID;
9096
}
9197

98+
BOOL FIRMessagingIsWatchKitExtension(void) {
99+
#if TARGET_OS_WATCH
100+
NSDictionary<NSString *, id> *infoDict = [[NSBundle mainBundle] infoDictionary];
101+
NSDictionary<NSString *, id> *extensionAttrDict = infoDict[@"NSExtension"];
102+
if (!extensionAttrDict) {
103+
return NO;
104+
}
105+
106+
NSString *extensionPointId = extensionAttrDict[@"NSExtensionPointIdentifier"];
107+
if (extensionPointId) {
108+
return [extensionPointId isEqualToString:kFIRMessagingWatchKitExtensionPoint];
109+
} else {
110+
return NO;
111+
}
112+
#else
113+
return NO;
114+
#endif
115+
}
116+
92117
uint64_t FIRMessagingGetFreeDiskSpaceInMB(void) {
93118
NSError *error;
94119
NSArray *paths =

FirebaseMessaging/Tests/UnitTests/FIRMessagingUtilitiesTest.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ - (void)testAppVersionReturnsEmptyStringWhenNotFound {
6969

7070
- (void)testAppIdentifierReturnsExpectedValue {
7171
#if TARGET_OS_WATCH
72+
NSDictionary *fakeInfoDictionary =
73+
@{@"NSExtension" : @{@"NSExtensionPointIdentifier" : @"com.apple.watchkit"}};
74+
[[[_mainBundleMock stub] andReturn:fakeInfoDictionary] infoDictionary];
7275
NSString *bundleIdentifier = @"com.me.myapp.watchkit.watchkitextensions";
7376
NSString *expectedIdentifier = @"com.me.myapp.watchkit";
7477
#else

0 commit comments

Comments
 (0)