From 954e4d5df13b14aee9c1112db67a23729d12acfd Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Mon, 9 Jul 2018 14:33:41 -0700 Subject: avoid calling [UIApplication sharedApplication] in app extensions (#1503) --- Firebase/Messaging/FIRMessagingReceiver.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Firebase/Messaging/FIRMessagingReceiver.m') diff --git a/Firebase/Messaging/FIRMessagingReceiver.m b/Firebase/Messaging/FIRMessagingReceiver.m index 981dfb1..7567eda 100644 --- a/Firebase/Messaging/FIRMessagingReceiver.m +++ b/Firebase/Messaging/FIRMessagingReceiver.m @@ -19,8 +19,9 @@ #import #import "FIRMessaging.h" -#import "FIRMessaging_Private.h" #import "FIRMessagingLogger.h" +#import "FIRMessagingUtilities.h" +#import "FIRMessaging_Private.h" static NSString *const kUpstreamMessageIDUserInfoKey = @"messageID"; static NSString *const kUpstreamErrorUserInfoKey = @"error"; @@ -111,19 +112,23 @@ static int downstreamMessageID = 0; SEL oldNotificationSelector = @selector(application:didReceiveRemoteNotification:); dispatch_async(dispatch_get_main_queue(), ^{ - id appDelegate = [[UIApplication sharedApplication] delegate]; + UIApplication *application = FIRMessagingUIApplication(); + if (!application) { + return; + } + id appDelegate = [application delegate]; if ([appDelegate respondsToSelector:newNotificationSelector]) { // Try the new remote notification callback - [appDelegate application:[UIApplication sharedApplication] - didReceiveRemoteNotification:message - fetchCompletionHandler:^(UIBackgroundFetchResult result) {}]; + [appDelegate application:application + didReceiveRemoteNotification:message + fetchCompletionHandler:^(UIBackgroundFetchResult result) { + }]; } else if ([appDelegate respondsToSelector:oldNotificationSelector]) { // Try the old remote notification callback #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [appDelegate application: - [UIApplication sharedApplication] didReceiveRemoteNotification:message]; + [appDelegate application:application didReceiveRemoteNotification:message]; #pragma clang diagnostic pop } else { FIRMessagingLoggerError(kFIRMessagingMessageCodeReceiver005, -- cgit v1.2.3