aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2018-05-30 17:59:18 -0700
committerGravatar Paul Beusterien <paulbeusterien@google.com>2018-05-30 18:01:55 -0700
commitf3d34f6179572d2bbe10a15399980247f6a359fd (patch)
treeaaf746f8dd18f15378c6bdd5aab7e781e635725a /Firebase
parented5c3217e89aafb25b6c11793cc0ab4a1c9d8d5c (diff)
App extension check (#1358)
Diffstat (limited to 'Firebase')
-rw-r--r--Firebase/Auth/Source/FIRAuth.m14
-rw-r--r--Firebase/Auth/Source/FIRAuthAppDelegateProxy.m14
-rw-r--r--Firebase/Auth/Source/FIRAuthDefaultUIDelegate.m15
3 files changed, 39 insertions, 4 deletions
diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m
index c83a19a..81008ca 100644
--- a/Firebase/Auth/Source/FIRAuth.m
+++ b/Firebase/Auth/Source/FIRAuth.m
@@ -19,6 +19,7 @@
#import "FIRAuth_Internal.h"
#import <FirebaseCore/FIRAppAssociationRegistration.h>
+#import <FirebaseCore/FIRAppEnvironmentUtil.h>
#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRLogger.h>
#import <FirebaseCore/FIROptions.h>
@@ -438,7 +439,18 @@ static NSMutableDictionary *gKeychainServiceNameForAppName;
_settings = [[FIRAuthSettings alloc] init];
_firebaseAppName = [appName copy];
#if TARGET_OS_IOS
- UIApplication *application = [UIApplication sharedApplication];
+
+ static Class applicationClass = nil;
+ // iOS App extensions should not call [UIApplication sharedApplication], even if UIApplication
+ // responds to it.
+ if (![FIRAppEnvironmentUtil isAppExtension]) {
+ Class cls = NSClassFromString(@"UIApplication");
+ if (cls && [cls respondsToSelector:NSSelectorFromString(@"sharedApplication")]) {
+ applicationClass = cls;
+ }
+ }
+ UIApplication *application = [applicationClass sharedApplication];
+
// Initialize the shared FIRAuthAppDelegateProxy instance in the main thread if not already.
[FIRAuthAppDelegateProxy sharedInstance];
#endif
diff --git a/Firebase/Auth/Source/FIRAuthAppDelegateProxy.m b/Firebase/Auth/Source/FIRAuthAppDelegateProxy.m
index f13e94f..3289b4e 100644
--- a/Firebase/Auth/Source/FIRAuthAppDelegateProxy.m
+++ b/Firebase/Auth/Source/FIRAuthAppDelegateProxy.m
@@ -16,6 +16,8 @@
#import "FIRAuthAppDelegateProxy.h"
+#import <FirebaseCore/FIRAppEnvironmentUtil.h>
+
#import <objc/runtime.h>
NS_ASSUME_NONNULL_BEGIN
@@ -200,8 +202,18 @@ static BOOL isIOS9orLater() {
+ (nullable instancetype)sharedInstance {
static dispatch_once_t onceToken;
static FIRAuthAppDelegateProxy *_Nullable sharedInstance;
+ // iOS App extensions should not call [UIApplication sharedApplication], even if UIApplication
+ // responds to it.
+ static Class applicationClass = nil;
+ if (![FIRAppEnvironmentUtil isAppExtension]) {
+ Class cls = NSClassFromString(@"UIApplication");
+ if (cls && [cls respondsToSelector:NSSelectorFromString(@"sharedApplication")]) {
+ applicationClass = cls;
+ }
+ }
+ UIApplication *application = [applicationClass sharedApplication];
dispatch_once(&onceToken, ^{
- sharedInstance = [[self alloc] initWithApplication:[UIApplication sharedApplication]];
+ sharedInstance = [[self alloc] initWithApplication:application];
});
return sharedInstance;
}
diff --git a/Firebase/Auth/Source/FIRAuthDefaultUIDelegate.m b/Firebase/Auth/Source/FIRAuthDefaultUIDelegate.m
index a00d0e9..e5aa7f4 100644
--- a/Firebase/Auth/Source/FIRAuthDefaultUIDelegate.m
+++ b/Firebase/Auth/Source/FIRAuthDefaultUIDelegate.m
@@ -16,6 +16,8 @@
#import "FIRAuthDefaultUIDelegate.h"
+#import <FirebaseCore/FIRAppEnvironmentUtil.h>
+
NS_ASSUME_NONNULL_BEGIN
@interface FIRAuthDefaultUIDelegate ()
@@ -58,8 +60,17 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (id<FIRAuthUIDelegate>)defaultUIDelegate {
- UIViewController *topViewController =
- [UIApplication sharedApplication].keyWindow.rootViewController;
+ // iOS App extensions should not call [UIApplication sharedApplication], even if UIApplication
+ // responds to it.
+ static Class applicationClass = nil;
+ if (![FIRAppEnvironmentUtil isAppExtension]) {
+ Class cls = NSClassFromString(@"UIApplication");
+ if (cls && [cls respondsToSelector:NSSelectorFromString(@"sharedApplication")]) {
+ applicationClass = cls;
+ }
+ }
+ UIApplication *application = [applicationClass sharedApplication];
+ UIViewController *topViewController = application.keyWindow.rootViewController;
while (true){
if (topViewController.presentedViewController) {
topViewController = topViewController.presentedViewController;