Skip to content

Commit

Permalink
[v11] Drop support for deprecated notification methods (#13064)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Jun 4, 2024
1 parent 926b678 commit 594abb8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 56 deletions.
4 changes: 1 addition & 3 deletions FirebaseMessaging/Sources/FIRMessaging.m
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,7 @@ - (void)handleIncomingLinkIfNeededFromMessage:(NSDictionary *)message {
// Similarly, |application:openURL:sourceApplication:annotation:| will also always be called,
// due to the default swizzling done by FIRAAppDelegateProxy in Firebase Analytics
} else if ([appDelegate respondsToSelector:openURLWithSourceApplicationSelector]) {
// TODO(Xcode 15): When Xcode 15 is the minimum supported Xcode version, it will be unnecessary to
// check if `TARGET_OS_VISION` is defined.
#if TARGET_OS_IOS && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION)
#if TARGET_OS_IOS
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[appDelegate application:application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ id FIRMessagingPropertyNameFromObject(id object, NSString *propertyName, Class k
}

#pragma mark - GULApplicationDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void)application:(GULApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
}
#pragma clang diagnostic pop

#if TARGET_OS_IOS || TARGET_OS_TV
- (void)application:(UIApplication *)application
Expand Down
6 changes: 4 additions & 2 deletions FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ + (BOOL)supportsSecureCoding {
}

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
id deviceToken = [aDecoder decodeObjectForKey:kFIRInstanceIDAPNSInfoTokenKey];
if (![deviceToken isKindOfClass:[NSData class]]) {
NSData *deviceToken = [aDecoder decodeObjectOfClass:[NSData class]
forKey:kFIRInstanceIDAPNSInfoTokenKey];
if (!deviceToken) {
return nil;
}

BOOL isSandbox = [aDecoder decodeBoolForKey:kFIRInstanceIDAPNSInfoSandboxKey];
return [self initWithDeviceToken:(NSData *)deviceToken isSandbox:isSandbox];
}
Expand Down
27 changes: 12 additions & 15 deletions FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,29 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
BOOL needsMigration = NO;
// These value cannot be nil

id authorizedEntity = [aDecoder decodeObjectForKey:kFIRInstanceIDAuthorizedEntityKey];
if (![authorizedEntity isKindOfClass:[NSString class]]) {
NSString *authorizedEntity = [aDecoder decodeObjectOfClass:[NSString class]
forKey:kFIRInstanceIDAuthorizedEntityKey];
if (!authorizedEntity) {
return nil;
}

id scope = [aDecoder decodeObjectForKey:kFIRInstanceIDScopeKey];
if (![scope isKindOfClass:[NSString class]]) {
NSString *scope = [aDecoder decodeObjectOfClass:[NSString class] forKey:kFIRInstanceIDScopeKey];
if (!scope) {
return nil;
}

id token = [aDecoder decodeObjectForKey:kFIRInstanceIDTokenKey];
if (![token isKindOfClass:[NSString class]]) {
NSString *token = [aDecoder decodeObjectOfClass:[NSString class] forKey:kFIRInstanceIDTokenKey];
if (!token) {
return nil;
}

// These values are nullable, so only fail the decode if the type does not match
// These values are nullable, so don't fail on nil.

id appVersion = [aDecoder decodeObjectForKey:kFIRInstanceIDAppVersionKey];
if (appVersion && ![appVersion isKindOfClass:[NSString class]]) {
return nil;
}
NSString *appVersion = [aDecoder decodeObjectOfClass:[NSString class]
forKey:kFIRInstanceIDAppVersionKey];
NSString *firebaseAppID = [aDecoder decodeObjectOfClass:[NSString class]
forKey:kFIRInstanceIDFirebaseAppIDKey];

id firebaseAppID = [aDecoder decodeObjectForKey:kFIRInstanceIDFirebaseAppIDKey];
if (firebaseAppID && ![firebaseAppID isKindOfClass:[NSString class]]) {
return nil;
}
NSSet *classes = [[NSSet alloc] initWithArray:@[ FIRMessagingAPNSInfo.class ]];
FIRMessagingAPNSInfo *rawAPNSInfo = [aDecoder decodeObjectOfClasses:classes
forKey:kFIRInstanceIDAPNSInfoKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,13 @@ @interface FakeAppDelegate : NSObject <GULApplicationDelegate>
@property(nonatomic, strong) NSError *registerForRemoteNotificationsError;
@end
@implementation FakeAppDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void)application:(GULApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
self.remoteNotificationMethodWasCalled = YES;
}
#pragma clang diagnostic pop

#if TARGET_OS_IOS || TARGET_OS_TV
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
self.remoteNotificationWithFetchHandlerWasCalled = YES;
completionHandler(UIBackgroundFetchResultNewData);
}
#endif

Expand Down Expand Up @@ -192,22 +186,26 @@ - (void)testSwizzlingNonAppDelegate {
#if !SWIFT_PACKAGE
// The next 3 tests depend on a sharedApplication which is not available in the Swift PM test env.
- (void)testSwizzledIncompleteAppDelegateRemoteNotificationMethod {
XCTestExpectation *expectation = [self expectationWithDescription:@"completion"];
IncompleteAppDelegate *incompleteAppDelegate = [[IncompleteAppDelegate alloc] init];
[[GULAppDelegateSwizzler sharedApplication] setDelegate:incompleteAppDelegate];
[self.proxy swizzleMethodsIfPossible];

NSDictionary *notification = @{@"test" : @""};
OCMExpect([self.mockMessaging appDidReceiveMessage:notification]);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[incompleteAppDelegate application:[GULAppDelegateSwizzler sharedApplication]
didReceiveRemoteNotification:notification];
#pragma clang diagnostic pop
didReceiveRemoteNotification:notification
fetchCompletionHandler:^(UIBackgroundFetchResult result) {
[expectation fulfill];
}];

[self.mockMessaging verify];
[self waitForExpectationsWithTimeout:0.5 handler:nil];
}

// This test demonstrates the difference between Firebase 10 and 11. In 10 and earlier the
// swizzler inserts the old `didReceiveRemoteNotification` method. In 11, the new.
- (void)testIncompleteAppDelegateRemoteNotificationWithFetchHandlerMethod {
IncompleteAppDelegate *incompleteAppDelegate = [[IncompleteAppDelegate alloc] init];
[[GULAppDelegateSwizzler sharedApplication] setDelegate:incompleteAppDelegate];
Expand All @@ -216,11 +214,11 @@ - (void)testIncompleteAppDelegateRemoteNotificationWithFetchHandlerMethod {
#if TARGET_OS_IOS || TARGET_OS_TV
SEL remoteNotificationWithFetchHandler = @selector(application:
didReceiveRemoteNotification:fetchCompletionHandler:);
XCTAssertFalse([incompleteAppDelegate respondsToSelector:remoteNotificationWithFetchHandler]);
XCTAssertTrue([incompleteAppDelegate respondsToSelector:remoteNotificationWithFetchHandler]);
#endif

SEL remoteNotification = @selector(application:didReceiveRemoteNotification:);
XCTAssertTrue([incompleteAppDelegate respondsToSelector:remoteNotification]);
XCTAssertFalse([incompleteAppDelegate respondsToSelector:remoteNotification]);
}

- (void)testSwizzledAppDelegateRemoteNotificationMethods {
Expand All @@ -230,29 +228,15 @@ - (void)testSwizzledAppDelegateRemoteNotificationMethods {

NSDictionary *notification = @{@"test" : @""};

// Test application:didReceiveRemoteNotification:

// Verify our swizzled method was called
OCMExpect([self.mockMessaging appDidReceiveMessage:notification]);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[appDelegate application:[GULAppDelegateSwizzler sharedApplication]
didReceiveRemoteNotification:notification];
#pragma clang diagnostic pop

// Verify our original method was called
XCTAssertTrue(appDelegate.remoteNotificationMethodWasCalled);
[self.mockMessaging verify];

// Test application:didReceiveRemoteNotification:fetchCompletionHandler:
#if TARGET_OS_IOS || TARGET_OS_TV
// Verify our swizzled method was called
OCMExpect([self.mockMessaging appDidReceiveMessage:notification]);

[appDelegate application:[GULAppDelegateSwizzler sharedApplication]
didReceiveRemoteNotification:notification
fetchCompletionHandler:^(UIBackgroundFetchResult result){
fetchCompletionHandler:^(UIBackgroundFetchResult result) {
XCTAssertEqual(result, UIBackgroundFetchResultNewData);
}];

// Verify our original method was called
Expand Down

0 comments on commit 594abb8

Please sign in to comment.