How to get CFBundleURLSchemes of an app in iOS Swift

早过忘川 提交于 2019-12-11 04:07:09

问题


I have made a demo project App1 in which I added a button which will redirect me to the installed app suppose App2("fitbit") I have gone through many tutorials and basically got the idea how to do this through the 2nd answer "This app is not allowed to query for scheme cydia" IOS9 error .but got stucked at a point where I need to mention URL Scheme of App2("fitbit") at LSApplicationQueriesSchemes in App1.

So basically the question is how to get the URL Schemes of the apps like fitbit.

and here are my codes

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)

        }

    }

回答1:


Use like this

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")!)
        }

and add this line into info.plist

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


来源:https://stackoverflow.com/questions/41934746/how-to-get-cfbundleurlschemes-of-an-app-in-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!