How to get CFBundleURLSchemes of an app in iOS Swi

2019-07-14 23:36发布

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.

enter image description here

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

enter image description here

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条回答
beautiful°
2楼-- · 2019-07-15 00:30

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>
查看更多
登录 后发表回答