簡體   English   中英

swift - 應用程序無法從另一個應用程序打開

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

我嘗試從我的應用程序中打開優步應用程序。 它直接將我重定向到應用商店,而不是應用。 我希望它直接打開優步應用程序,而不是通過應用商店應用程序。 這是我的 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)
    }
}

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

編輯

使用uber值將LSApplicationQueriesSchemes鍵添加到Info.plist

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

優步文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM