16

I just upgrade my phone to iOS 10.2.1.

In my Swift App (using 3.0), I am trying to check if Google Maps is installed on the phone. If yes, open this address in Google Maps.

UIApplication.shared.canOpenURL(NSURL(string:"comgooglemaps://")! as URL)

Even though I have Google Maps installed, the expression evaluates to false.

Oddly I can open Google Maps in Swift with this

UIApplication.shared.open(NSURL(string:
            "comgooglemaps://?saddr=&daddr=\(lat),\(lon)&directionsmode=driving")! as URL, options: [:], completionHandler: nil)

Was there some kind of change in iOS 10.2.1 that prevents the first expression from evaluating to be true?

The URL seems to be the same (comgooglemaps)

Is there something required now in the plist?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Ray Saudlach
  • 530
  • 1
  • 6
  • 19

1 Answers1

24

What you are implementing is legal, but you have to add the URL schemes to the application info.plist, by adding LSApplicationQueriesSchemes array and appending "comgooglemaps" to it:

LSApplicationQueriesSchemes (Array - iOS) Specifies the URL schemes you want the app to be able to use with the canOpenURL: method of the UIApplication class. For each URL scheme you want your app to use with the canOpenURL: method, add it as a string in this array. Read the canOpenURL: method description for important information about declaring supported schemes and using that method.

It should be -somewhat- similar to:

enter image description here

For more information, you might want to check the documentation (mentioned above).

computingfreak
  • 4,939
  • 1
  • 34
  • 51
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
  • When searching for this in the plist editor nowadays, the property is called `Queried URL Schemes`. Of course, you can still use the source code editor and add the `LSApplicationQueriesSchemes` array. – Jan Erik Schlorf Aug 17 '23 at 11:28