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
Share:
3,402
lsaudon
Author by

lsaudon

I'm developper

Updated on December 14, 2022

Comments

  • lsaudon
    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
      Richard over 4 years
      Agreed. 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
      Richard over 4 years
      Addendum... 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
      Richard over 4 years
      Compared 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
      lsaudon over 4 years
      I find this solution dev.to/robotsquidward/…, but I don't know how to implement it in objective-c and flutter.
    • lsaudon
      lsaudon over 4 years
      For flutter developers, check pub.dev/packages/flutter_web_auth
  • Turnipdabeets
    Turnipdabeets about 3 years
    What's the difference between using #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 or if #available(iOS 13.0, *)?