本文介绍了如何将我当前的位置分享给UIActivityViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以在UIActivityViewController中添加文本,URL,图像等内容,但是如何使用我的位置缩略图添加我当前的位置,如下面显示的推文中所示?换句话说,如何在UIActivityViewController中共享坐标latitude,longitude?
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 ?
谢谢
推荐答案
我有一个完整的代码示例以及执行此操作的所有重要类/方法。我知道答案很晚,但这可能有助于将来的某些人:
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];
}
}];
}
这篇关于如何将我当前的位置分享给UIActivityViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!