[英]How to share text and image on facebook wall (objective C)
我正在开发一个应用程序,用户可以将他们的应用程序的详细信息分享到Facebook。 我有UITableview,它包含作者姓名列表,当你点击书名时,它会转到另一个UITableView
,在那里它显示每个TableViewCell
中该作者的不同书。 我能够在第二个UITableView
显示列表。 我想知道如何分享作者姓名,书名和图像(第2张表格详情)。 我正在展示那样做的代码。所以当用户想要分享细节时,他将不得不点击作者UITableView
每个单元格中的UIButton
。
didselectatindexpath
NSDictionary *selectedAuthor = nil;
NSArray *sectionArray=[mainIndexDictionary objectForKey:[allKeysArray objectAtIndex:indexPath.section]];
selectedAuthor = [sectionArray objectAtIndex:indexPath.row];
iPath=[[selectedAuthor objectForKey:@"SymptIndexID"] intValue];
NSLog(@"iPath - %d",iPath);
authortitleString=[[selectedAuthor objectForKey:@"authorIndexName"]stringByAppendingString:@" cure!"];
}
bookArray=[objDB customCellData:(NSInteger)iPath];
[self.view bringSubviewToFront:authorView];
[bookTableView scrollRectToVisible:CGRectMake(0.0, 0.0, 320.0,10.0) animated:NO];
[bookTableView reloadData]
;
在ios 6.0中,您可以实现如下(您必须将社交框架添加到您的项目中)
#import <Social/Social.h>
- (void)ShareFacebook
{
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]autorelease];
[alert show];
}
}
你的问题有点不清楚,但考虑到你已经正确实现了FB ios Api的所有其他方法,你可以使用这段代码将文本和图像发布到Fb
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
APP_NAME,@"text", fb_app_url,@"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
APP_NAME, @"name",
fb_app_url, @"link",
fb_publish_image, @"picture",
APP_NAME, @"name",
@"Awesome APP", @"caption",
[NSString stringWithFormat:@"I am loving it", GAME_NAME], @"description",
@"Get it now!", @"message",
actionLinksStr, @"action_links",
nil];
[self.faceBook dialog:@"stream.publish" andParams:params andDelegate:self];
有关实现fb api的更多详细信息,您可以看到
如何将Facebook整合到iPhone应用程序中 输入链接描述
此链接显示发布消息时允许的参数http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.