diff options
author | Chen Liang <chliang@google.com> | 2018-07-09 14:33:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-09 14:33:41 -0700 |
commit | 954e4d5df13b14aee9c1112db67a23729d12acfd (patch) | |
tree | debab82666deb5d7ff1e99d55f5dba749db1ffb1 /Firebase/Messaging/FIRMessagingReceiver.m | |
parent | bd69fae81077dd1107e4abe8a8722cb3d8a5fb29 (diff) |
avoid calling [UIApplication sharedApplication] in app extensions (#1503)
Diffstat (limited to 'Firebase/Messaging/FIRMessagingReceiver.m')
-rw-r--r-- | Firebase/Messaging/FIRMessagingReceiver.m | 19 |
1 files changed, 12 insertions, 7 deletions
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 <UIKit/UIKit.h> #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<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate]; + UIApplication *application = FIRMessagingUIApplication(); + if (!application) { + return; + } + id<UIApplicationDelegate> 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, |