我正在尝试构建一个应用程序,可以共享地址并在任何导航应用程序中打开(如Google地图,Apple地图,waze等)。以下是我目前拥有的代码(经过了很多谷歌搜索结果和数十个stackoverflow问题的筛选)。
当我在模拟器上运行应用程序时,我会得到以下结果:
点击分享按钮后
为什么我没有像苹果地图或谷歌地图这样的应用程序建议?我也不明白为什么它建议我将其复制到联系人中。
提前致谢。
@IBAction func navigeer(_ sender: Any) {
var items = [AnyObject]()
let latitude: Double = 52.033809
let longitude: Double = 6.882286
let locationTitle = "Navigate to this address"
let URLString = "https://maps.apple.com?ll=\(latitude),\(longitude)"
guard let cachesPathString = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first else {
print("Error: couldn't find the caches directory.")
return
}
if let url = NSURL(string: URLString) {
items.append(url)
}
let vCardString = [
"BEGIN:VCARD",
"VERSION:3.0",
"N:;Shared Location;;;",
"FN:Shared Location",
"item1.URL;type=pref:http://maps.apple.com/?ll=\(latitude),\(longitude)",
"item1.X-ABLabel:map url",
"END:VCARD"
].joined(separator: "\n")
let vCardFilePath = (cachesPathString as NSString).appendingPathComponent("vCard.loc.vcf")
let nsVCardData = NSURL(fileURLWithPath: vCardFilePath)
let shareItems:Array = [nsVCardData]
let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
present(activityController, animated:true, completion: nil)
}
当我在模拟器上运行应用程序时,我会得到以下结果:
点击分享按钮后
![After clicking the share button](https://istack.dev59.com/ROtqk.webp)
提前致谢。