如何在Facebook墙上分享文本和图片(Objective-C)

5

我正在开发一个应用程序,它允许用户将其应用程序的详细信息分享到 Facebook 上。我有一个 UITableview,其中包含作者名称列表,当您点击书名时,它会进入另一个UITableView,在每个 TableViewCell 中显示该作者不同的书籍。我能够在第二个 UITableView 中显示列表。 我想知道如何分享作者姓名、书名和图片(第二个 tableView 中的详细信息)。 这是实现此功能的代码... 因此,当用户想要分享详细信息时,他将不得不点击每个作者 < code > 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]

;
2个回答

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];
 }
}

请访问以下链接:http://www.techotopia.com/index.php/An_iPhone_iOS_6_Facebook_Integration_Tutorial_using_UIActivityViewController - umer sufyan
我怎样可以发布我的当前位置? - Agent Chocks.

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/


我想显示从iPath获取的标题名称以及iPath的详细信息(书名,流派等)..详细信息是从SQL数据库中获取的..我想知道如何处理它。 - raptor
将actionlinks的第二个参数替换为iPath,第三个参数是可以通过URL获取的图像(您可以将所有图像放在URL中,并通过XML访问它们)。如果您没有任何托管,而且想要将静态图像发布到xcode项目中的墙壁上,则必须查看Facebook API,那里有一些方法允许发布图像数据。 - hariszaman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接