我正在尝试将 Facebook 登录上的共享集成到我的应用程序中,但不知何故,我无法实现在 Facebook 墙上共享位置的目的,这里我使用社交框架。
我尝试的代码如下:
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(@"Cancelled.....");
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(@"Posted....");
}
break;
}};
[fbController setInitialText:@"This is My Sample Text"];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sign in!" message:@"Please first Sign In!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
这样我就可以分享初始文本,但我需要分享的是当前位置。
提前致谢。
最佳答案
对于此导入 MapKit 框架,您可以使用 CLLocationManger 获取当前位置。
NSString *city;
CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
CLLocationCoordinate2D coordinate = [locationManager.location coordinate];
GeoCodeValue=[[NSString alloc] initWithFormat:@"%f,%f",coordinate.latitude,coordinate.longitude];
NSLog(@"userLocation::%@",GeoCodeValue);
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:locationManager.location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
city = placemark.thoroughfare;
}];
&将此城市字符串作为文本传递以显示当前位置。
[fbController setInitialText:@"Current Location is %@",city"];
关于ios - 使用社交框架在 Facebook 墙上分享位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29138338/