Skip to content

Commit 2f8c8d1

Browse files
authored
Merge pull request #122 from pi-chan/enable-safariview
Open authorize url in SFSafariViewController when available
2 parents 2bee46a + 4d84db7 commit 2f8c8d1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ios/OAuthManager/OAuthManager.m

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#import <Foundation/Foundation.h>
88
#import <UIKit/UIKit.h>
99
#import <objc/runtime.h>
10+
#import <SafariServices/SafariServices.h>
1011

1112
#import "OAuthManager.h"
1213
#import "DCTAuth.h"
@@ -29,6 +30,7 @@ @implementation OAuthManager
2930
static NSString *const AUTH_MANAGER_TAG = @"AUTH_MANAGER";
3031
static OAuthManager *manager;
3132
static dispatch_once_t onceToken;
33+
static SFSafariViewController *safariViewController = nil;
3234

3335
RCT_EXPORT_MODULE(OAuthManager);
3436

@@ -85,7 +87,13 @@ + (BOOL)setupOAuthHandler:(UIApplication *)application
8587

8688
[authPlatform setURLOpener: ^void(NSURL *URL, DCTAuthPlatformCompletion completion) {
8789
// [sharedManager setPendingAuthentication:YES];
88-
[application openURL:URL];
90+
if ([SFSafariViewController class] != nil) {
91+
safariViewController = [[SFSafariViewController alloc] initWithURL:URL];
92+
UIViewController *viewController = application.keyWindow.rootViewController;
93+
[viewController presentViewController:safariViewController animated:YES completion: nil];
94+
} else {
95+
[application openURL:URL];
96+
}
8997
completion(YES);
9098
}];
9199

@@ -112,6 +120,9 @@ + (BOOL)handleOpenUrl:(UIApplication *)application openURL:(NSURL *)url
112120
NSString *strUrl = [manager stringHost:url];
113121

114122
if ([manager.callbackUrls indexOfObject:strUrl] != NSNotFound) {
123+
if(safariViewController != nil) {
124+
[safariViewController dismissViewControllerAnimated:YES completion:nil];
125+
}
115126
return [DCTAuth handleURL:url];
116127
}
117128

0 commit comments

Comments
 (0)