2015-03-19 59 views
2

我正在尝试在Facebook上集成共享登录在我的应用程序中,但不知何故,我无法实现这一点,因为我在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]; 
    } 

这个我可以分享的初始文本,但我需要的是分享的是当前位置。
在此先感谢。

+0

想用图形API?【检查】(http://stackoverflow.com/questions/20329083/how- to-share-location-on-facebook-with-message-using-https-graph-faceboo) – 2015-03-19 06:43:38

+0

@UmangBista你有没有理解这个问题? – 2015-03-19 06:48:21

+0

你想要: '文字发布'感觉'位置'感谢? – 2015-03-19 06:52:31

回答

2

对于此导入的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; 
}]; 

&通这个城市的字符串作为文字显示当前location.as

[fbController setInitialText:@"Current Location is %@",city"];