How to close SFSafariViewController automatically

2020-08-25 05:33发布

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条回答
姐就是有狂的资本
2楼-- · 2020-08-25 05:59

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().

查看更多
登录 后发表回答