在特定网址上关闭SFSafariViewController [英] Closes SFSafariViewController on a certain url

查看:264
本文介绍了在特定网址上关闭SFSafariViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到达某个页面时,我正在尝试关闭SFSafariViewController.

I am trying to close SFSafariViewController when I reach a certain page.

但是在明确按下完成"按钮之前,我无法执行此操作 由用户.

But I am unable to do it until the "Done" button is pressed explicitly by the user.

我想要的是在到达特定页面后立即获取URL,然后关闭视图控制器. 然后,我可以使用

What I want is to get the URL as soon as it reached a certain page and then dismiss the view controller. Then I can pick the rest using this

func safariViewControllerDidFinish(_ controller: SFSafariViewController){
    // do work here
}

注意:曾有人问过这个问题,但我找不到任何问题 满意的答案

Note: This question has been asked before but I was unable to find any satisfactory answers

推荐答案

如果为您的应用程序注册URI方案,则页面上可能会有一个链接,可将您带回您的应用程序.届时您将进入

If you register a URI scheme for your app, you could have have a link on a page which takes you back to your app. At that point you'll be in

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

您的AppDelegate,您可以做任何您想做的事.

of your AppDelegate and you can do whatever you wish.

由于Safari View Controller可以访问用户的 凭据,通过iCloud钥匙串在其所有设备上同步, 登录将变得轻而易举.[…]需要两个步骤.首先 是您使用自己的应用内浏览器的地方,只需显示一个 SFSafariViewController的实例.

"Because since Safari View Controller has access to a user’s credentials, synced across all of their devices with iCloud Keychain, logging in is going to be a breeze.[…] It takes two steps. The first is where you would’ve used your own in-app browser, just present an instance of SFSafariViewController.

并且一旦用户完成登录和第三方网站 服务使用您自定义的URL方案重定向回您的应用 喂它,您可以在AppDelegate的handleOpenURL中接受它 方法.

And once the user is finished logging in and the third-party web service redirects back to your app with the custom URL scheme that you fed it, you can accept that in your AppDelegate‘s handleOpenURL method.

您可以在此处检查响应并关闭实例 SFSafariViewController,因为您知道身份验证是 完成.

From there you can inspect the response and dismiss the instance of SFSafariViewController because you know that the authentication is done.

就是这样.两步."

来源: http://asciiwwdc.com/2015/sessions/504#t = 1558.026

请注意,不推荐使用handleOpenURL方法,而推荐使用application:openURL:options:.

Please note the handleOpenURL method is deprecated in favor of application:openURL:options:.

这篇关于在特定网址上关闭SFSafariViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆