ios - 如何在 Swift 应用程序中使用自定义 URL 打开另一个 Swift 应用程序

标签 ios swift3 deep-linking custom-url

我为 Swift 应用程序设置了自定义 URL。我想在另一个应用程序的按钮操作上使用此 URL 进行深层链接。我试过 UIApplication.shared.open(NSURL(string: "redirectToApp://Testapp/startPage")! as URL, options: [:], completionHandler: nil) 但是,它不工作.有什么建议吗?

更新:

redirectToApp://Testapp/startPage 从 Safari 打开应用。

谢谢!

最佳答案

确保您编写的代码带有错误检查/处理功能,这样您就可以找出问题所在。

像这样尝试:

    if let url = URL(string: "redirectToApp://Testapp/startPage")
    {
        if UIApplication.shared.canOpenURL(url)
        {
            UIApplication.shared.open(url, options: [:], completionHandler: {
                (success) in
                if (success)
                {
                    print("OPENED \(url): \(success)")
                }
                else
                {
                    print("FAILED to open \(url)")
                }
            })
        }
        else
        {
            print("CANNOT open \(url)")
        }
    }

关于ios - 如何在 Swift 应用程序中使用自定义 URL 打开另一个 Swift 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44549174/

相关文章:

iOS 7 presentViewController 显示黑屏和 SIGABRT

ios - 在NSMutableArray中快速找到子字符串

Swift 将数据从 TabBarController 传递到 TableViewController

apple-push-notifications - UNUserNotificationCenter didRecieve 应用终止时不调用响应

ios - 使用 iOS 10.2 版在同一设备上获取不同的 UUID

swift - NSView dataWithPDF inside rect 但有背景 View

ios - iOS 9+ 问题的 Branch.io 链接

android - 来自浏览器的深度链接无法运行 Android

android - 来自 JetpackNavigation 库中通知的隐式深层链接

ios - 在散点图上绘制置信椭圆