【发布时间】:2018-07-10 10:04:33
【问题描述】:
我知道之前有人问过并回答过这个问题,但我仍然在调试器控制台中收到此错误。
2018-07-10 12:55:15.173843+0300 清洁工[34011:2595874] -canOpenURL:URL 失败:“comgooglemaps://” - 错误:“操作无法完成。(OSStatus 错误 -10814。)”
环境:Xcode 9.4、Swift 3。
请告知我如何修复我的实施。希望其他人也会发现它有用。
Info.plist 文件
<key>NSLocationWhenInUseUsageDescription</key>
<string>Will you allow myApp to know your location?</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>
和代码;
func openMapsApp(destinationLatitude:String, destinationLongitude:String, cleanerAddressNow:String) {
self.locationManager.stopUpdatingLocation()
guard let _ = self.cleanerCurrentLatitude else {
print("cleanerCurrentLatitude not received line \(#line)")
return
}
guard let _ = self.cleanerCurrentLongitude else {
print("cleanerCurrentLongitude not received line \(#line)")
return
}
//For Apple Maps
let testURL2 = URL.init(string: "http://maps.apple.com/")
//For Google Maps
let testURL = URL.init(string: "comgooglemaps://")
guard let _ = testURL2 else {return}
guard let _ = testURL else {return}
//For Google Maps
if UIApplication.shared.canOpenURL(testURL!) {
let sourceAddress = cleanerAddressNow.replacingOccurrences(of: " ", with: "+")
let direction = String(format: "comgooglemaps://?daddr=%@&dirflg=%@&x-success=sourceapp://?resume=true&x-source=AirApp", sourceAddress,"r")
let directionsURL = URL.init(string: direction)
if #available(iOS 10, *) {
UIApplication.shared.open(directionsURL!)
} else {
UIApplication.shared.openURL(directionsURL!)
}
}
//For Apple Maps
else if UIApplication.shared.canOpenURL(testURL2!) {
let sourceAddress = cleanerAddressNow.replacingOccurrences(of: " ", with: "+")
let direction = String(format: "http://maps.apple.com/?daddr=%@&dirflg=%@", sourceAddress,"r")
let directionsURL = URL.init(string: direction)
if #available(iOS 10, *) {
UIApplication.shared.open(directionsURL!)
} else {
UIApplication.shared.openURL(directionsURL!)
}
}
//For SAFARI Browser
else {
let sourceAddress = cleanerAddressNow.replacingOccurrences(of: " ", with: "+")
let direction = String(format: "http://maps.apple.com/?daddr=%@&dirflg=%@", sourceAddress,"r")
let directionsURL = URL.init(string: direction)
if #available(iOS 10, *) {
UIApplication.shared.open(directionsURL!)
} else {
UIApplication.shared.openURL(directionsURL!)
}
}
}
【问题讨论】:
-
你解决了吗?
-
我做了,请看下面的答案
-
@NavNav 我的回答解决了你的问题吗?
标签: google-maps swift3