Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

ios - How to share my current location to UIActivityViewController?

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 ? in other words how to share coordinates "latitude,longitude" in UIActivityViewController ?

Thanks

a tweet with location

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have a complete example of code and all the important classes/methods to do this. I know the answer is very late, but this may help someone in the future:

- (void)shareTab
{
    PFGeoPoint *geoPoint = self.vidgeoObject[kParseLocation];
    NSString *coordinates = [NSString stringWithFormat:@"http://maps.apple.com/maps?q=%f,%f",  geoPoint.latitude, geoPoint.longitude];
    CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:geoPoint.latitude longitude:geoPoint.longitude];
    CLGeocoder *geocoder;
    geocoder = [[CLGeocoder alloc]init];

    [geocoder reverseGeocodeLocation:userLocation completionHandler:^(NSArray *placemarks, NSError *error)
    {
        CLPlacemark *rootPlacemark = placemarks[0];
        MKPlacemark *evolvedPlacemark = [[MKPlacemark alloc]initWithPlacemark:rootPlacemark];

        ABRecordRef persona = ABPersonCreate();
        ABRecordSetValue(persona, kABPersonFirstNameProperty, (__bridge CFTypeRef)(evolvedPlacemark.name), nil);
        ABMutableMultiValueRef multiHome = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);

        bool didAddHome = ABMultiValueAddValueAndLabel(multiHome, (__bridge CFTypeRef)(evolvedPlacemark.addressDictionary), kABHomeLabel, NULL);

        if(didAddHome)
        {
            ABRecordSetValue(persona, kABPersonAddressProperty, multiHome, NULL);

            NSLog(@"Address saved.");
        }

        NSArray *individual = [[NSArray alloc]initWithObjects:(__bridge id)(persona), nil];
        CFArrayRef arrayRef = (__bridge CFArrayRef)individual;
        NSData *vcards = (__bridge NSData *)ABPersonCreateVCardRepresentationWithPeople(arrayRef);

        NSString* vcardString;
        vcardString = [[NSString alloc] initWithData:vcards encoding:NSASCIIStringEncoding];
        NSLog(@"%@",vcardString);


        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory

        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"pin.loc.vcf"];
        [vcardString writeToFile:filePath
                              atomically:YES encoding:NSUTF8StringEncoding error:&error];

        NSURL *url =  [NSURL fileURLWithPath:filePath];
        NSLog(@"url> %@ ", [url absoluteString]);


        // Share Code //
        NSArray *itemsToShare = [[NSArray alloc] initWithObjects: url, nil] ;
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
        activityVC.excludedActivityTypes = @[UIActivityTypePrint,
                                             UIActivityTypeCopyToPasteboard,
                                             UIActivityTypeAssignToContact,
                                             UIActivityTypeSaveToCameraRoll,
                                             UIActivityTypePostToWeibo];

        if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
        {
            [self presentViewController:activityVC animated:YES completion:nil];
        } else
        {
        popControl = [[UIPopoverController alloc] initWithContentViewController:activityVC];
        }

    }];

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...