OGeek|极客世界-中国程序员成长平台

标题: ios - 使用社交框架在 Facebook 墙上分享位置 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:41
标题: ios - 使用社交框架在 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(@"osted....");
                }
                    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"lease first Sign In!" delegate:nil cancelButtonTitle"ok" otherButtonTitles:nil, nil];
        [alert show];
    }

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



Best Answer-推荐答案


你可以使用 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;
}];

& 将此城市字符串作为文本传递以显示当前位置.as

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

关于ios - 使用社交框架在 Facebook 墙上分享位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29138338/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4