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
2930static NSString *const AUTH_MANAGER_TAG = @" AUTH_MANAGER" ;
3031static OAuthManager *manager;
3132static dispatch_once_t onceToken;
33+ static SFSafariViewController *safariViewController = nil ;
3234
3335RCT_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