我很擅长将Facebook整合到iOS应用程序中。我已经阅读了3本书,研究了Facebook的例子,并研究了Facebook的教程,而且我不了解Facebook的整合。我理解如何在Facebook上注册应用程序,但我不明白的是将文本和图片发布到用户新闻源的代码。我试图了解Facebook的教程,但它们都基于Xcode和iOS版本,这些版本不是最新版本。 Facebook的教程也不一致(例如,登录教程与发布教程中的变量不匹配等)。我确实理解如何将文本添加到“initialText”,但是在Facebook策略中提供此变量中的默认文本。任何人都可以解释如何在Xcode中将文本和图片发布到用户的新闻源吗?
感谢名单!
答案 0 :(得分:1)
你试过这个吗?
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"ResultCancelled");
} else
{
NSLog(@"ResultSuccess");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:@"Learn iOS6 Social Framework integration"];
[controller addURL:[NSURL URLWithString:@"http://google.com"]];
[controller addImage:[UIImage imageNamed:@"myimage.jpeg"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else{
//NSLog(@"UnAvailable");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Facebook"
message:[NSStringstringWithFormat:@"The application cannot post message at the moment. Please login under setting section with your Facebook account."]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
答案 1 :(得分:0)
在您的项目中导入社交框架。
- (void)ShareOnFB
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"Cancelled");
} else
{
NSLog(@"Done");
//Adding the Text to the facebook post value from iOS
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
NSString *fb=[NSString stringWithFormat:@"you can add your text hereand change it as and when needed"];
[controller setInitialText:fb];
//Adding the Image to the facebook post value from iOS
[controller addImage:yourImageView.image];
[self presentViewController:controller animated:YES completion:Nil];
}