swift-应用程序无法从其他应用程序打开

问题描述 投票:-1回答:1

我尝试通过我的应用打开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)
            }
            }
ios swift xcode nsurlconnection func
1个回答
0
投票

我认为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")!)
}
© www.soinside.com 2019 - 2024. All rights reserved.