如何在 iOS Swift 中获取应用程序的 CFBundleURLSchemes

How to get CFBundleURLSchemes of an app in iOS Swift

我制作了一个演示项目 App1,其中我添加了一个按钮,该按钮会将我重定向到已安装的应用程序假设 App2("fitbit") 我已经学习了很多教程并且通过第二个答案 基本上知道了如何做到这一点。但在我需要提及 URL App2 方案(“fitbit ") 在 App1 中的 LSApplicationQueriesSchemes。

所以基本上问题是如何获得 fitbit.[=16= 等应用程序的 URL 方案]

这是我的代码

var url  = NSURL(string: "itms://itunes.apple.com/in/app/fitbit/id462638897?mt=8")
@IBAction func redirectOnclick(_ sender: Any) {
        let urlFitBt  = NSURL(string: "fitbit://")
        if UIApplication.shared.canOpenURL(urlFitBt! as URL)
        {
            UIApplication.shared.open(urlFitBt! as URL)
        }
        else
        {
            UIApplication.shared.open(url! as URL)

        }

    }

这样使用

swift 2.2

        let fitbit = "fitbit://"    //this is fitbit URLSCHEME
        let fitbiturl = NSURL(string: fitbit)

        if UIApplication.sharedApplication().canOpenURL(fitbiturl!)
        {
            UIApplication.sharedApplication().openURL(fitbiturl!)

        } else {
            UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/gb/app/fitbit/id462638897?mt=8&ign-mpt=uo%3D2")!)
        }

并将此行添加到 info.plist

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fitbit</string>
    </array>