-
-
Save ElegyD/510a17904917a7e7326254b824da1b2f to your computer and use it in GitHub Desktop.
Create a location vCard for use in UIActivityViewController like in Apple's Maps app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreLocation | |
static func vCardURL(from coordinate: CLLocationCoordinate2D, with name: String?) -> URL { | |
let vCardFileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("vCard.loc.vcf") | |
let vCardString = [ | |
"BEGIN:VCARD", | |
"VERSION:4.0", | |
"FN:\(name ?? "Shared Location")", | |
"item1.URL;type=pref:http://maps.apple.com/?ll=\(coordinate.latitude),\(coordinate.longitude)", | |
"item1.X-ABLabel:map url", | |
"END:VCARD" | |
].joined(separator: "\n") | |
do { | |
try vCardString.write(toFile: vCardFileURL.path, atomically: true, encoding: .utf8) | |
} catch let error { | |
print("Error, \(error.localizedDescription), saving vCard: \(vCardString) to file path: \(vCardFileURL.path).") | |
} | |
return vCardFileURL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment