1

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:

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)
    }
}
emrcftci
  • 3,355
  • 3
  • 21
  • 35
Pawel Zet
  • 41
  • 1
  • 7

1 Answers1

1

I think the else statement get called because maybe "Uber://" is a not valid key to open the app directly.

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

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

Uber Documentation

emrcftci
  • 3,355
  • 3
  • 21
  • 35
  • Tried it but still the same issue – Pawel Zet Apr 07 '20 at 11:29
  • this means `canOpenURL()` returns false and it directs you to appstore, so could you please share more details? like the result of print `UIApplication.shared.canOpenURL(url)` `false` etc. – emrcftci Apr 07 '20 at 12:35
  • Thats the log: ```-canOpenURL: failed for URL: "uber://" - error: "This app is not allowed to query for scheme uber" 2020-04-07 16:07:14.632232+0200 Toasty Kiepscy[4558:1033901] Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.``` – Pawel Zet Apr 07 '20 at 14:08
  • 1
    @PawelZet please check my edited answer, I hope it will work – emrcftci Apr 07 '20 at 14:13
  • Cool, works now! Thank you :) I would know it in the future. – Pawel Zet Apr 07 '20 at 18:50
  • @emrcftci, Hi emrcfci , How to find the URL. I need to open swedbank private app. But cannot find the url. It always redirect to app store. – Saravanan Jun 21 '21 at 13:25
  • @Saravanan Have you found the solution? i experienced the same thing – Ali Jan 27 '22 at 05:01
  • @emrcftci Is there any other way to get the key (uber) other than reading the documentation? because the application I want to open has no documentation – Ali Jan 27 '22 at 05:05
  • maybe this SO question will help y'all -> https://stackoverflow.com/questions/52318063/find-the-url-scheme-of-an-app-on-my-iphone – emrcftci Jan 27 '22 at 05:45
  • @Ali Hi, Are you using wkwebview? before entering swish payment app? – Saravanan Jan 28 '22 at 12:27
  • @Saravanan I don't use wkwebview – Ali Jan 31 '22 at 07:21
  • @emrcftci Thank you for your reference, really appreciate it – Ali Jan 31 '22 at 08:43