我正在开发一款应用程序,可让用户将自己应用的详细信息分享到Facebook。我有UITableview,其中包含作者姓名列表,当您点击书名时,它会转到另一个UITableView
,其中显示每个TableViewCell
中该作者的不同书籍。我可以在第二个UITableView
中显示列表。
我想知道如何分享作者姓名,书名和图像(第2张表格详情)。
我正在展示那样做的代码..
因此,当用户想要分享详细信息时,他必须点击作者UIButton
的每个单元格中的UITableView
。
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]
;
答案 0 :(得分:10)
在ios 6.0中 您可以实现如下(您必须将social framework添加到您的项目中)
#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];
}
}
答案 1 :(得分:1)
您的问题有点不清楚,但考虑到您已经正确实施了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的更多详细信息,您可以看到
How to integrate Facebook into iPhone App enter link description here
此链接显示发布消息时允许的参数 http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/