For some reason, not all of the time but most of the time, the SFSafariViewControllerDelegate method for initialLoadDidRedirectTo is not being triggered for subsequent reloads as specified in the docs.
@discussion This method may be called even after -safariViewController:didCompleteInitialLoad: if
the web page performs additional redirects without user interaction.
I am allowing a user to log in with an OAuth 2.0 Provider on the Safari browser and expecting to detect the redirect to continue the flow from the app once their credentials have securely been consumed by the IdP in Safari.
It was working consistently. It went from a 100% success rate up until this week to maybe 1/20 successful redirects.
Code snippet:
let config = SafariViewController.Configuration()
config.entersReaderIfAvailable = false
let vc = SFSafariViewController(url: url, configuration: config)
vc.delegate = self
self.safariViewController = vc
print(self.safariViewController?.delegate)
self.present(vc, animated: true)
Why is it not always detecting the redirects?
Post
Replies
Boosts
Views
Activity
This method does not seem to work consistently: SFSafariViewControllerDelegate.safariViewController(_ controller: SFSafariViewController, initialLoadDidRedirectTo URL: URL)
It was working 100% of the time until this week for me, now it has about a 1-5% success rate for detecting redirects.
The docs are not clear:
@discussion This method may be called even after -safariViewController:didCompleteInitialLoad: if
the web page performs additional redirects without user interaction.
Code snippet from calling UIViewController that conforms to SFSafariViewControllerDelegate:
let config = SafariViewController.Configuration()
config.entersReaderIfAvailable = false
let vc = SFSafariViewController(url: url, configuration: config)
vc.delegate = self
self.safariViewController = vc
print(self.safariViewController?.delegate)
self.present(vc, animated: true)
Did something change? How can I make this consistent again?
I am trying to auth with a non-apple auth provider for a multi-platform service. I'm expecting to be able to use this to fetch the OAuth code after the user logs in to their auth provider.
myRedirectHost = 'https' OR 'https://my.domain.com' where I also know the redirect path and query params and will extract them.
ASWebAuthenticationSession(url: url, callbackURLScheme: myRedirectHost, completionHandler: handleAuthSessionResult)
This works for iOS 17.4+ with that nice enum, but what about the rest of the users?