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

swift - App does not open from another app

我尝试从我的应用程序打开优步应用程序。它会将我直接重定向到应用商店,而不是应用程序。我希望它直接打开 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")!)
}

编辑

LSApplicationQueriesSchemes 键添加到 Info.plistuber

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>uber</string>
</array>

Uber Documentation