2015-03-19 41 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"];