4

I need to check whether the user has installed Google Maps on the phone . If Google Maps is installed, open Google Maps, else open Apple Maps. But even when Google Maps is not installed 'canOpenURL' returns true.

Here’s my code,

if (UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!)){
        let urlString = "comgooglemaps://?center=" + lat + "," + long + "&q=" + lat + "," + long
        let url = URL(string: urlString)
        UIApplication.shared.openURL(url!)
    }else{
        let urlString:NSString = NSString(format: "http://maps.apple.com/?q=%@,%@", lat, long)
        UIApplication.shared.openURL(URL(string: urlString as String)!)
    }

And, I have added LSApplicationQueriesSchemes array and appended "comgooglemaps" to it.

Info.plist Image here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
NavodaP
  • 218
  • 3
  • 18

0 Answers0