Skip to content

Commit 09920d1

Browse files
authored
[Messaging] Update TARGET_OS_* conditionals (#13184)
1 parent f24850f commit 09920d1

17 files changed

+77
-81
lines changed

FirebaseMessaging/Sources/FIRMessaging.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ - (void)configureMessagingWithOptions:(FIROptions *)options {
221221
// This is not needed for app extension except for watch.
222222
#if TARGET_OS_WATCH
223223
[self didCompleteConfigure];
224-
#else
224+
#else // TARGET_OS_WATCH
225225
if (![GULAppEnvironmentUtil isAppExtension]) {
226226
[self didCompleteConfigure];
227227
}
228-
#endif
228+
#endif // TARGET_OS_WATCH
229229
}
230230

231231
- (void)didCompleteConfigure {
@@ -393,7 +393,7 @@ - (BOOL)handleContextManagerMessage:(NSDictionary *)message {
393393
}
394394

395395
- (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message {
396-
#if TARGET_OS_IOS || TARGET_OS_TV
396+
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
397397
NSURL *url = [self linkURLFromMessage:message];
398398
if (url == nil) {
399399
return;
@@ -415,11 +415,9 @@ - (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message {
415415
SEL openURLWithOptionsSelector = @selector(application:openURL:options:);
416416
SEL openURLWithSourceApplicationSelector = @selector(application:
417417
openURL:sourceApplication:annotation:);
418-
// TODO(Xcode 15): When Xcode 15 is the minimum supported Xcode version, it will be unnecessary to
419-
// check if `TARGET_OS_VISION` is defined.
420-
#if TARGET_OS_IOS && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION)
418+
#if TARGET_OS_IOS
421419
SEL handleOpenURLSelector = @selector(application:handleOpenURL:);
422-
#endif // TARGET_OS_IOS && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION)
420+
#endif // TARGET_OS_IOS
423421
// Due to FIRAAppDelegateProxy swizzling, this selector will most likely get chosen, whether or
424422
// not the actual application has implemented
425423
// |application:continueUserActivity:restorationHandler:|. A warning will be displayed to the user
@@ -440,9 +438,7 @@ - (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message {
440438
// Similarly, |application:openURL:sourceApplication:annotation:| will also always be called,
441439
// due to the default swizzling done by FIRAAppDelegateProxy in Firebase Analytics
442440
} else if ([appDelegate respondsToSelector:openURLWithSourceApplicationSelector]) {
443-
// TODO(Xcode 15): When Xcode 15 is the minimum supported Xcode version, it will be unnecessary to
444-
// check if `TARGET_OS_VISION` is defined.
445-
#if TARGET_OS_IOS && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION)
441+
#if TARGET_OS_IOS
446442
#pragma clang diagnostic push
447443
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
448444
[appDelegate application:application
@@ -455,9 +451,9 @@ - (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message {
455451
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
456452
[appDelegate application:application handleOpenURL:url];
457453
#pragma clang diagnostic pop
458-
#endif // TARGET_OS_IOS && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION)
454+
#endif // TARGET_OS_IOS
459455
}
460-
#endif // TARGET_OS_IOS || TARGET_OS_TV
456+
#endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
461457
}
462458

463459
- (NSURL *)linkURLFromMessage:(NSDictionary *)message {

FirebaseMessaging/Sources/FIRMessagingContextManagerService.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ + (UNMutableNotificationContent *)contentFromContextualMessage:(NSDictionary *)m
173173
if (apsDictionary[kFIRMessagingContextManagerBadgeKey]) {
174174
content.badge = apsDictionary[kFIRMessagingContextManagerBadgeKey];
175175
}
176-
#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH
176+
#if !TARGET_OS_TV
177177
// The following fields are not available on tvOS
178178
if ([apsDictionary[kFIRMessagingContextManagerBodyKey] length]) {
179179
content.body = apsDictionary[kFIRMessagingContextManagerBodyKey];
@@ -201,7 +201,7 @@ + (UNMutableNotificationContent *)contentFromContextualMessage:(NSDictionary *)m
201201
if (userInfo.count) {
202202
content.userInfo = userInfo;
203203
}
204-
#endif // TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH
204+
#endif // !TARGET_OS_TV
205205
return content;
206206
}
207207

FirebaseMessaging/Sources/FIRMessagingExtensionHelper.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ - (void)populateNotificationContent:(UNMutableNotificationContent *)content
111111
self.bestAttemptContent = content;
112112

113113
// The `userInfo` property isn't available on newer versions of tvOS.
114-
#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH
114+
#if !TARGET_OS_TV
115115
NSObject *currentImageURL = content.userInfo[kPayloadOptionsName][kPayloadOptionsImageURLName];
116116
if (!currentImageURL || currentImageURL == [NSNull null]) {
117117
[self deliverNotification];
@@ -131,12 +131,12 @@ - (void)populateNotificationContent:(UNMutableNotificationContent *)content
131131
@"The Image URL provided is invalid %@.", currentImageURL);
132132
[self deliverNotification];
133133
}
134-
#else
134+
#else // !TARGET_OS_TV
135135
[self deliverNotification];
136-
#endif
136+
#endif // !TARGET_OS_TV
137137
}
138138

139-
#if TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_WATCH
139+
#if !TARGET_OS_TV
140140
- (NSString *)fileExtensionForResponse:(NSURLResponse *)response {
141141
NSString *suggestedPathExtension = [response.suggestedFilename pathExtension];
142142
if (suggestedPathExtension.length > 0) {
@@ -194,7 +194,7 @@ - (void)loadAttachmentForURL:(NSURL *)attachmentURL
194194
completionHandler(attachment);
195195
}] resume];
196196
}
197-
#endif
197+
#endif // !TARGET_OS_TV
198198

199199
- (void)deliverNotification {
200200
if (self.contentHandler) {

FirebaseMessaging/Sources/FIRMessagingRemoteNotificationsProxy.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ - (void)application:(GULApplication *)application
392392
}
393393
#pragma clang diagnostic pop
394394

395-
#if TARGET_OS_IOS || TARGET_OS_TV
395+
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
396396
- (void)application:(UIApplication *)application
397397
didReceiveRemoteNotification:(NSDictionary *)userInfo
398398
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
@@ -408,7 +408,7 @@ - (void)application:(UIApplication *)application
408408
@"application:didFailToRegisterForRemoteNotificationsWithError: %@",
409409
error.localizedDescription);
410410
}
411-
#endif
411+
#endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
412412

413413
- (void)application:(GULApplication *)application
414414
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

FirebaseMessaging/Sources/FIRMessagingUtilities.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ int64_t FIRMessagingCurrentTimestampInMilliseconds(void) {
8989
} else {
9090
return bundleID;
9191
}
92-
#else
92+
#else // TARGET_OS_WATCH
9393
return bundleID;
94-
#endif
94+
#endif // TARGET_OS_WATCH
9595
}
9696

9797
NSString *FIRMessagingFirebaseAppID(void) {
@@ -112,17 +112,17 @@ BOOL FIRMessagingIsWatchKitExtension(void) {
112112
} else {
113113
return NO;
114114
}
115-
#else
115+
#else // TARGET_OS_WATCH
116116
return NO;
117-
#endif
117+
#endif // TARGET_OS_WATCH
118118
}
119119

120120
NSSearchPathDirectory FIRMessagingSupportedDirectory(void) {
121121
#if TARGET_OS_TV
122122
return NSCachesDirectory;
123-
#else
123+
#else // TARGET_OS_TV
124124
return NSApplicationSupportDirectory;
125-
#endif
125+
#endif // TARGET_OS_TV
126126
}
127127

128128
#pragma mark - Locales
@@ -315,10 +315,10 @@ BOOL FIRMessagingIsProductionApp(void) {
315315
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
316316
NSString *path = [[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]
317317
stringByAppendingPathComponent:@"embedded.provisionprofile"];
318-
#elif TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_VISION
318+
#else // TARGET_OS_OSX || TARGET_OS_MACCATALYST
319319
NSString *path = [[[NSBundle mainBundle] bundlePath]
320320
stringByAppendingPathComponent:@"embedded.mobileprovision"];
321-
#endif
321+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
322322

323323
if ([GULAppEnvironmentUtil isAppStoreReceiptSandbox] && !path.length) {
324324
// Distributed via TestFlight

FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ - (NSMutableDictionary *)keychainQueryForService:(NSString *)service account:(NS
9292
NSMutableDictionary *keychainQuery = [self keychainQueryForService:service account:account];
9393
NSMutableArray<NSData *> *results;
9494
keychainQuery[(__bridge id)kSecReturnData] = (__bridge id)kCFBooleanTrue;
95-
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
95+
#if TARGET_OS_OSX || TARGET_OS_WATCH
96+
keychainQuery[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;
97+
NSData *passwordInfos =
98+
CFBridgingRelease([[FIRMessagingKeychain sharedInstance] itemWithQuery:keychainQuery]);
99+
#else // TARGET_OS_OSX || TARGET_OS_WATCH
96100
keychainQuery[(__bridge id)kSecReturnAttributes] = (__bridge id)kCFBooleanTrue;
97101
keychainQuery[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;
98102
// FIRMessagingKeychain should only take a query and return a result, will handle the query here.
99103
NSArray *passwordInfos =
100104
CFBridgingRelease([[FIRMessagingKeychain sharedInstance] itemWithQuery:keychainQuery]);
101-
#elif TARGET_OS_OSX || TARGET_OS_WATCH
102-
keychainQuery[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;
103-
NSData *passwordInfos =
104-
CFBridgingRelease([[FIRMessagingKeychain sharedInstance] itemWithQuery:keychainQuery]);
105-
#endif
105+
#endif // TARGET_OS_OSX || TARGET_OS_WATCH
106106

107107
if (!passwordInfos) {
108108
// Nothing was found, simply return from this sync block.
@@ -119,17 +119,17 @@ - (NSMutableDictionary *)keychainQueryForService:(NSString *)service account:(NS
119119
return @[];
120120
}
121121
results = [[NSMutableArray alloc] init];
122-
#if TARGET_OS_IOS || TARGET_OS_TV
122+
#if TARGET_OS_OSX || TARGET_OS_WATCH
123+
[results addObject:passwordInfos];
124+
#else // TARGET_OS_OSX || TARGET_OS_WATCH
123125
NSInteger numPasswords = passwordInfos.count;
124126
for (NSUInteger i = 0; i < numPasswords; i++) {
125127
NSDictionary *passwordInfo = [passwordInfos objectAtIndex:i];
126128
if (passwordInfo[(__bridge id)kSecValueData]) {
127129
[results addObject:passwordInfo[(__bridge id)kSecValueData]];
128130
}
129131
}
130-
#elif TARGET_OS_OSX || TARGET_OS_WATCH
131-
[results addObject:passwordInfos];
132-
#endif
132+
#endif // TARGET_OS_OSX || TARGET_OS_WATCH
133133
// We query the keychain because it didn't exist in cache, now query is done, update the result in
134134
// the cache.
135135
if ([service isEqualToString:kFIRMessagingKeychainWildcardIdentifier] ||

FirebaseMessaging/Sources/Token/FIRMessagingTokenManager.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ - (void)tokenWithAuthorizedEntity:(NSString *)authorizedEntity
194194
return;
195195
}
196196

197-
#if TARGET_OS_SIMULATOR && TARGET_OS_IOS
197+
#if TARGET_OS_SIMULATOR
198198
if (tokenOptions[kFIRMessagingTokenOptionsAPNSKey] != nil) {
199199
// If APNS token is available on iOS Simulator, we must use the sandbox profile
200200
// https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
201201
tokenOptions[kFIRMessagingTokenOptionsAPNSIsSandboxKey] = @(YES);
202202
}
203-
#endif
203+
#endif // TARGET_OS_SIMULATOR
204204

205205
if (tokenOptions[kFIRMessagingTokenOptionsAPNSKey] != nil &&
206206
tokenOptions[kFIRMessagingTokenOptionsAPNSIsSandboxKey] == nil) {
@@ -689,17 +689,17 @@ - (void)setAPNSToken:(NSData *)APNSToken withUserInfo:(NSDictionary *)userInfo {
689689
return;
690690
}
691691
// Use this token type for when we have to automatically fetch tokens in the future
692-
#if TARGET_OS_SIMULATOR && TARGET_OS_IOS
692+
#if TARGET_OS_SIMULATOR
693693
// If APNS token is available on iOS Simulator, we must use the sandbox profile
694694
// https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
695695
BOOL isSandboxApp = YES;
696-
#else
696+
#else // TARGET_OS_SIMULATOR
697697
NSInteger type = [userInfo[kFIRMessagingAPNSTokenType] integerValue];
698698
BOOL isSandboxApp = (type == FIRMessagingAPNSTokenTypeSandbox);
699699
if (type == FIRMessagingAPNSTokenTypeUnknown) {
700700
isSandboxApp = FIRMessagingIsSandboxApp();
701701
}
702-
#endif
702+
#endif // TARGET_OS_SIMULATOR
703703

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

FirebaseMessaging/Tests/IntegrationTests/FIRMessagingPubSubTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@
7676
wait(for: [expectation], timeout: 5)
7777
}
7878
}
79-
#endif // !TARGET_OS_OSX
79+
#endif // !os(OSX)

FirebaseMessaging/Tests/IntegrationTests/FIRMessagingTokenRefreshTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@
145145
return app.options.gcmSenderID
146146
}
147147
}
148-
#endif // !TARGET_OS_OSX
148+
#endif // !os(OSX)

FirebaseMessaging/Tests/UnitTests/FIRMessagingAnalyticsTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,4 @@ - (void)testDisplayNotification {
488488
}
489489
@end
490490

491-
#endif
491+
#endif // TARGET_OS_IOS

0 commit comments

Comments
 (0)