0

我正在尝试通过社交媒体分享我的应用程序。特别是fb,但我不能分享我的帖子。

我需要点击我设计中特别给出的按钮..

我使用了下面的编码:

NSString *facebookShareLink = @"http://google.com";
NSString *titleToShare = @"Title";

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"fb://publish/profile/me?text=%@", facebookShareLink]];

if([[UIApplication sharedApplication] canOpenURL:url])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:facebookShareLink]  ];

} else
{

    NSString *facebookLink = [NSString stringWithFormat:@"https://www.facebook.com/login.php?next=https%3A%2F%2Fwww.facebook.com%2Fsharer%2Fsharer.php%3Fu%3D%2525%2540%26t%3D%2525%2540&display=popup", facebookShareLink, titleToShare];
    facebookLink = [facebookLink stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:facebookLink]];
}

取自 StackOverflow 本身..

谁能帮我解决这个问题..

4

1 回答 1

0

我试试这个.. 最初将 sociamedia.framework 添加到项目中。然后在类文件 .h 或 .m. 中导入框架。

-(IBAction)facebookPost:(id)sender{
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock =  ^(SLComposeViewControllerResult result){
    if (result == SLComposeViewControllerResultCancelled)
    {
        NSLog(@"Cancelled");
    }
    else
    {
        NSLog(@"Done");
    }
    [controller dismissViewControllerAnimated:YES completion:nil];
};
controller.completionHandler =myBlock;
//Adding the Text to the facebook post value from iOS
[controller setInitialText:@"My test post"];
//Adding the URL to the facebook post value from iOS
[controller addURL:[NSURL URLWithString:@"http://www.test.com"]];
//Adding the Text to the facebook post value from iOS
[self presentViewController:controller animated:YES completion:nil];
}
于 2014-08-08T11:40:49.453 回答