I know i can add things like text, URL, images to UIActivityViewController , but how to add my current location with a thumbnail of my location like in the tweet shown below
The other two answers use the complex AddressBook framework to create a vCard. It's easier to do it like this:
NSString *vcardString = [NSString stringWithFormat:@"BEGIN:VCARD\n"
"VERSION:3.0\n"
" N:;Shared Location;;;\n"
" FN:Shared Location\n"
"item1.URL;type=pref:http://maps.apple.com/?ll=%f,%f\n"
"item1.X-ABLabel:map url\n"
"END:VCARD", lat, lng];
Then save it to a file, get the NSURL of that file, and share it with UIActivityViewController as demonstrated in artillery129's answer.
The correct way is to make the card using Data, not a file:
Swift 4
import MobileCoreServices
let locationTitle: String = ...
let coordinate: CLLocationCoordinate2D = ...
let vCardString = [
"BEGIN:VCARD",
"VERSION:4.0",
"N:;\(locationTitle);;;",
"FN:\(locationTitle)",
"item1.URL;type=pref:http://maps.apple.com/?ll=\(coordinate.latitude),\(coordinate.longitude)",
"item1.X-ABLabel:map url",
"END:VCARD"
].joined(separator: "\n")
guard let vCardData = vCardString.data(using: .utf8) else { return }
var items = [Any]()
let vCardActivity = NSItemProvider(item: vCardData as NSData, typeIdentifier: kUTTypeVCard as String)
items.append(vCardActivity)
items.append(locationTitle)
let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)