Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect URL change in SFSafariViewController

I have a SFSafariViewController which opens when a user taps on a link in my app. I need to detect when the URL is changed, such that when it changes, the app displays an alert. How do we detect URL changes in SFSafariViewController?

like image 454
user2181948 Avatar asked Feb 12 '17 20:02

user2181948


1 Answers

You cannot do this.

SFSafariViewController is meant to send users off to a browser without caring too much where she goes to, but when she's done, she'll be right back in your app without any loss of context. There's only very few things you can customize.

The official docs mention (emphasis mine):

If your app lets users view websites from anywhere on the Internet, use the SFSafariViewController class. If your app customizes, interacts with, or controls the display of web content, use the WKWebView class.

It will require more work (especially some UI) to provide a nice browsing experience using WKWebView, but you're in control. The same goes for the older sibling, UIWebView. If you don't know which to use, this comparison might help, although some things may have improved on the side of WKWebView since the article was written.

like image 163
hagi Avatar answered Sep 21 '22 17:09

hagi