How to close SFSafariViewController automatically when reaching a certain page

7.7k views Asked by At

I want to close SFSafariViewController automatically upon reaching the "thank you" page of the Dropbox site after the user uploads something; it needs to automatically dismiss. How can I do that?

Here is what I have so far:

@IBAction func Singles5(_ sender: Any) {
    let safariVC = SFSafariViewController(url: NSURL(string: "https://www.dropbox/Upload")! as URL)
    self.present(safariVC, animated: true, completion: nil)
    safariVC.delegate = self
}
1

There are 1 answers

0
an23lm On

One way I can think of is using the Custom URL scheme. You can specify your app's custom URL in the callback parameter of Dropbox (if Dropbox has callback). So when the user has finished uploading his/her file, dropbox executes the callback. In this case your app will receive the callback, with any parameters have you specified. This will call the function application(app, open, options)->Bool in your AppDelegate. Now, you can use a reference to the ViewController which presents the SFSafariViewController and call SafariViewController.dissmissViewController().