5

我正在开发一个应用程序,它让用户可以将他们的应用程序的详细信息分享到 facebook 中。我有 UITableview ,其中包含作者姓名列表,当您单击书名时,它会转到另一个UITableView显示该作者的不同书籍的地方TableViewCell。我可以在 2nd 中显示列表UITableView。我想知道如何分享作者姓名、书名和图片(第二个表格视图详细信息)。我正在展示执行此操作的代码.. 因此,当用户想要分享详细信息时,他将不得不点击UIButtonauthor 的每个单元格中的那个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]

;
4

2 回答 2

10

在 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];
 }
}
于 2013-03-22T19:09:29.670 回答
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 的更多详细信息,您可以查看

如何将 Facebook 集成到 iPhone 应用程序中 在此处输入链接描述

此链接显示发布消息时允许的参数 http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/

于 2013-03-22T17:35:24.450 回答