-
-
Save souzainf3/3c7b0b072c28da7dbb905ee4b875dffb 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 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use