-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid calling [UIApplication sharedApplication] in app extensions #1503
Conversation
#ifdef COCOAPODS | ||
#import <GoogleUtilities/GULAppEnvironmentUtil.h> | ||
#else | ||
#import "third_party/firebase/ios/Source/GoogleUtilities/Environment/third_party/GULAppEnvironmentUtil.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't publish internal paths - let copybara make the translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some questions about behavior, but mostly LGTM.
Firebase/Messaging/FIRMessaging.m
Outdated
@@ -611,7 +611,8 @@ - (BOOL)shouldBeConnectedAutomatically { | |||
// We require a token from Instance ID | |||
NSString *token = self.defaultFcmToken; | |||
// Only on foreground connections | |||
UIApplicationState applicationState = [UIApplication sharedApplication].applicationState; | |||
UIApplication *application = FIRMessagingUIApplication(); | |||
UIApplicationState applicationState = application.applicationState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may return UIApplicationStateActive
for extensions regardless of the host application state. Is that the correct behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't finalized the official support for extensions so any function is called in extensions is not guarantee to be working. This CL just to ensure compilation works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If developer wants to establish a MCS connection in app extensions, it should probably work so the application state is for extension app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no, the application object would be nil, so there's no way to check the application state in extensions. Basically we should return no for this case.
I'm also adding nil check for all the cases here.
@@ -98,7 +99,8 @@ - (void)swizzleMethodsIfPossible { | |||
return; | |||
} | |||
|
|||
NSObject<UIApplicationDelegate> *appDelegate = [[UIApplication sharedApplication] delegate]; | |||
UIApplication *application = FIRMessagingUIApplication(); | |||
NSObject<UIApplicationDelegate> *appDelegate = [application delegate]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a nil-check here before swizzling?
check the UIApplication is nil before swizzling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This should make FCM compilable inside app extensions as requested by #1490