简体   繁体   English

swift - 应用程序无法从另一个应用程序打开

[英]swift - App does not open from another app

I try to open Uber app from my app.我尝试从我的应用程序中打开优步应用程序。 It redirects me straight to the appstore, not to the app.它直接将我重定向到应用商店,而不是应用。 I would like it to open Uber app directly not via appstore app.我希望它直接打开优步应用程序,而不是通过应用商店应用程序。 Here is my function:这是我的 function:

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)
    }
}

I think the else statement get called because maybe "Uber://" is a not valid key to open the app directly.我认为else语句被调用是因为"Uber://"可能是直接打开应用程序的无效键。

Maybe this will work for you也许这对你有用

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")!)
}

EDIT编辑

Add LSApplicationQueriesSchemes key to Info.plist with uber value使用uber值将LSApplicationQueriesSchemes键添加到Info.plist

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

Uber Documentation 优步文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM