使用社交框架在Facebook墙上共享位置

时间:2015-03-19 06:20:09

标签: ios objective-c 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];
    }

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

1 个答案:

答案 0 :(得分:2)

你可以使用CLLocationManger获取当前位置,就像这个导入MapKit框架一样。

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"];