ios - 使用社交框架在 Facebook 墙上分享位置

标签 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];
    }

这样我就可以分享初始文本,但我需要分享的是当前位置。
提前致谢。

最佳答案

对于此导入 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/

相关文章:

iOS - 无法在模拟器上写入文件

facebook - 如何在window.fbAsyncInit外调用FB.api

android - 如何使用数字用户 ID 在 Android 应用程序中打开 Facebook 个人资料

android - Ionic 框架 facebook 登录集成

ios - Apple App Store 审批问题

ios - 在 UIDatePicker 中选择特定日期?

ios - 如何找到 UILabel 的行高?

iphone - 音频单元 : How to get rid of popping/clicking at the start and end of tones?

iphone - 内部分布澄清

ios - 使用 UISegmentedControl 改变 Table View 的数据