ASWebAuthenticationSession on iOS 13
3,402
I find a solution
Add above the implementation.
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
@interface AppDelegate() <ASWebAuthenticationPresentationContextProviding>
@end
#endif
In your code for Auth.
self.authSessionAS = [[ASWebAuthenticationSession alloc]initWithURL:[[NSURL alloc] initWithString:self.authUrl] callbackURLScheme:@"app://" completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {
if(callbackURL)
{
self.resultStream(callbackURL.absoluteString);
}else
{
self.resultStream(@"");
}
self.resultStream = NULL;
}];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13, *)) {
self.authSessionAS.presentationContextProvider = self;
}
#endif
[self.authSessionAS start];
Add method
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
#pragma mark - ASWebAuthenticationPresentationContextProviding
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session API_AVAILABLE(ios(13.0)){
return UIApplication.sharedApplication.keyWindow;
}
#endif
Comments
-
lsaudon over 1 year
I installed iOS 13, the authentication via Safari no longer works. I have the same configuration on iOS 12 except
self.authSessionAS.presentationContextProvider = self;
self.authSessionAS = [[ASWebAuthenticationSession alloc]initWithURL:[[NSURL alloc] initWithString:self.authUrl] callbackURLScheme:@"app://" completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) { if(callbackURL) { self.resultStream(callbackURL.absoluteString); }else { self.resultStream(@""); } self.resultStream = NULL; }]; self.authSessionAS.presentationContextProvider = self; [self.authSessionAS start];
-
Richard over 4 yearsAgreed. Have some code that runs on both iOS 12 and 13... With iOS 12, it correctly detects the cookie and uses it to prefill the login screen. With iOS 13, it doesn't detect the cookie and presents the default login screen. Presumably a bug in iOS 13...
-
Richard over 4 yearsAddendum... If the app is compiled in Xcode 10 (iOS 12 release) then ASWebAuthenticationSession broadly works on iOS 13 (although it doesn't pick up the cookie).
-
Richard over 4 yearsCompared to Xcode 11, where ASWebAuthenticationSession doesn't work on iOS 13 at all -- completely broken. Don't know what happens if compiled on Xcode 11 and run on iOS 12.
-
lsaudon over 4 yearsI find this solution dev.to/robotsquidward/…, but I don't know how to implement it in objective-c and flutter.
-
lsaudon over 4 yearsFor flutter developers, check pub.dev/packages/flutter_web_auth
-
-
Turnipdabeets about 3 yearsWhat's the difference between using
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
orif #available(iOS 13.0, *)
?