问题
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