UIApplication.shared.canOpenURL(URL(字符串:“comgooglemaps://”)!)始终返回true

时间:2017-08-15 09:31:49

标签: ios swift google-maps

我需要检查用户是否在手机上安装了Google地图。如果已安装Google地图,请打开Goog​​le地图,否则请打开Apple地图。 但即使未安装Google地图,'canOpenURL'也会返回true。

这是我的代码,

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

并且,我添加了LSApplicationQueriesSchemes数组并附加了“comgooglemaps”。

Info.plist Image here

0 个答案:

没有答案