27
27
static NSString *const kFIRMessagingAPNSSandboxPrefix = @" s_" ;
28
28
static NSString *const kFIRMessagingAPNSProdPrefix = @" p_" ;
29
29
30
+ static NSString *const kFIRMessagingWatchKitExtensionPoint = @" com.apple.watchkit" ;
31
+
30
32
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
31
33
static NSString *const kEntitlementsAPSEnvironmentKey = @" Entitlements.aps-environment" ;
32
34
#else
@@ -76,10 +78,14 @@ int64_t FIRMessagingCurrentTimestampInMilliseconds(void) {
76
78
NSString *FIRMessagingAppIdentifier (void ) {
77
79
NSString *bundleID = [[NSBundle mainBundle ] bundleIdentifier ];
78
80
#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
+ }
83
89
#else
84
90
return bundleID;
85
91
#endif
@@ -89,6 +95,25 @@ int64_t FIRMessagingCurrentTimestampInMilliseconds(void) {
89
95
return [FIROptions defaultOptions ].googleAppID ;
90
96
}
91
97
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
+
92
117
uint64_t FIRMessagingGetFreeDiskSpaceInMB (void ) {
93
118
NSError *error;
94
119
NSArray *paths =
0 commit comments