How to share my current location to UIActivityViewController?

前端 未结 8 1393
别那么骄傲
别那么骄傲 2020-12-05 12:32

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

8条回答
  •  被撕碎了的回忆
    2020-12-05 12:56

    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.

提交回复
热议问题