|
16 | 16 | #import <TargetConditionals.h>
|
17 | 17 | #if TARGET_OS_IOS
|
18 | 18 |
|
| 19 | +#import <GoogleUtilities/GULAppEnvironmentUtil.h> |
19 | 20 | #import <UIKit/UIKit.h>
|
20 | 21 | #import "FirebaseAuth/Sources/Auth/FIRAuth_Internal.h"
|
21 | 22 | #import "FirebaseAuth/Sources/MultiFactor/TOTP/FIRTOTPSecret+Internal.h"
|
@@ -60,10 +61,28 @@ - (NSString *)generateQRCodeURLWithAccountName:(NSString *)accountName issuer:(N
|
60 | 61 |
|
61 | 62 | - (void)openInOTPAppWithQRCodeURL:(NSString *)QRCodeURL {
|
62 | 63 | NSURL *url = [NSURL URLWithString:QRCodeURL];
|
63 |
| - if ([[UIApplication sharedApplication] canOpenURL:url]) { |
64 |
| - [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; |
| 64 | + static Class applicationClass = nil; |
| 65 | + // iOS App extensions should not call [UIApplication sharedApplication], even if UIApplication |
| 66 | + // responds to it. |
| 67 | + if (![GULAppEnvironmentUtil isAppExtension]) { |
| 68 | + Class cls = NSClassFromString(@"UIApplication"); |
| 69 | + if (cls && [cls respondsToSelector:@selector(sharedApplication)]) { |
| 70 | + applicationClass = cls; |
| 71 | + } |
| 72 | + } |
| 73 | + UIApplication *application = [applicationClass sharedApplication]; |
| 74 | + if (application) { |
| 75 | + if ([application respondsToSelector:@selector(canOpenURL:)]) { |
| 76 | + if ([application canOpenURL:url]) { |
| 77 | + [application openURL:url options:@{} completionHandler:nil]; |
| 78 | + } else { |
| 79 | + NSLog(@"URL cannot be opened"); |
| 80 | + } |
| 81 | + } else { |
| 82 | + NSLog(@"Cannot access canOpenURL: method"); |
| 83 | + } |
65 | 84 | } else {
|
66 |
| - FIRLogError(kFIRLoggerAuth, @"I-AUT000019", @"URL cannot be opened"); |
| 85 | + NSLog(@"sharedApplication cannot be accessed"); |
67 | 86 | }
|
68 | 87 | }
|
69 | 88 |
|
|
0 commit comments