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

Har*_*oel 2 objective-c url-scheme ios fitbit swift

我已经制作了一个演示项目App1,其中我添加了一个按钮,它将重定向到安装的应用程序假设App2(" fitbit ")我已经通过了很多教程,基本上知道如何通过第二个答案"这个应用程序不允许查询方案cydia"IOS9错误.但是我需要在App1中的LSApplicationQueriesSchemes中提到App2的URL方案(" fitbit ").

在此输入图像描述

所以基本上问题是如何获得像fitbit这样的应用程序的URL Schemes .

在此输入图像描述

这是我的代码

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)

        }

    }
Run Code Online (Sandbox Code Playgroud)

IOS*_*ngh 5

像这样使用

迅捷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")!)
        }
Run Code Online (Sandbox Code Playgroud)

并将此行添加到info.plist中

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fitbit</string>
    </array>
Run Code Online (Sandbox Code Playgroud)