我尝试通过我的应用打开Uber应用。它直接将我重定向到应用商店,而不是应用。我希望它不通过appstore应用程序直接打开Uber应用程序。这是我的功能:
func callUrl(){
if let url = NSURL(string: "Uber://"), UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.open(url as URL)
} else if let itunesUrl = NSURL(string: "https://apps.apple.com/us/app/uber/id368677368"), UIApplication.shared.canOpenURL(itunesUrl as URL) {
UIApplication.shared.open(itunesUrl as URL)
}
}
我认为else
语句会被调用,因为"Uber://"
可能不是直接打开应用程序的无效键。
也许这对您有用
if let url = URL(string: "uber://"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
else {
UIApplication.shared.open(URL(string: "https://apps.apple.com/us/app/uber/id368677368")!)
}