我需要检查用户是否在手机上安装了Google地图。如果已安装Google地图,请打开Google地图,否则请打开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”。