我正在尝试通过社交媒体分享我的应用。特别是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本身..
任何人都可以帮我解决这个问题。
答案 0 :(得分: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];
}