【问题标题】:Opening universal links in embedded SFSafariViewController在嵌入式 SFSafariViewController 中打开通用链接
【发布时间】:2020-10-22 22:15:18
【问题描述】:

我目前正在集成安全登录提供程序,他们的 SDK 使用模式 SFSafariView 打开登录页面。

要求不同于他们作为标准提供的要求,我们需要有一个访客按钮来关闭模式并链接到应用程序中的其他位置。 - 由于这不是标准,SDK 无法处理。

除非用户强制单击链接并选择在我们的应用程序中打开,否则链接将继续指向 SFSafariView 中的网页。这不是很好的用户体验,除了在网页上添加注释(不是很吸引人)之外,没有其他方法可以通知用户这种需求。

Q - 如何获取 SFSafariView 中显示的 html 网页上显示的链接,以便将其发送到打开的同一个应用程序。 注意 - 该应用程序具有关联的域并在站点上正确设置了 AASA 文件

有用的代码

//Sets up a SFSafariVC (use this code in a button to open a local html file with your link in)
guard let path = Bundle.main.path(forResource: "", ofType: "html") else { return }
let url = URL(fileURLWithPath: path)
let config = SFSafariViewController.Configuration()
let vc = SFSafariViewController(url: url, configuration: config)
present(vc, animated: true)

【问题讨论】:

    标签: ios swift ios-universal-links sfsafariviewcontroller


    【解决方案1】:

    使用老式的深层链接确实解决了我的问题。

    通过注册自定义 URL 协议

        <key>CFBundleURLTypes</key>
        <array>
            <dict>
            <key>CFBundleURLName</key>
              <string>com.appName.app</string>
              <key>CFBundleURLSchemes</key>
              <array>
                <string>appNameWebProtocol</string>
              </array>
            </dict>
        </array>
    

    然后使用 appNameWebProtocol://link/destination 形式的链接,SFSafariViewController 总是将此链接传递给应用程序。

    这是由 appDelegate 方法获取的

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

    此解决方案的问题 - 在我们的特定情况下,此链接可以在可以在应用程序外部查看且无需安装的网站上找到。如果是这种情况,链接将不会执行任何操作,因此我们的解决方案必须在网页上包含自定义脚本,以确定它应该在网页中显示哪个链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多