xcode 如何在 facebook 墙上分享文字和图片(目标 C)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15553495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:02:15  来源:igfitidea点击:

How to share text and image on facebook wall (objective C)

iosobjective-ciphonexcodeuitableview

提问by raptor

I am working on an app which provides user to share the details of their app into facebook . I have UITableview where it contains the list of author name and when u click on book name it goes to another UITableViewwhere it shows the different book of that author in each TableViewCell. I'm able to display the list in 2nd UITableView. I wanted to know how to share the author name , book name and the image (2nd tableview details). I'm showing the code which does that .. So when the user wants to share the details, he will have to tap on the UIButtonwhich is there in every cell of author UITableView.

我正在开发一个应用程序,该应用程序可让用户将其应用程序的详细信息分享到 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]

;

回答by umer sufyan

In ios 6.0 you can achieve as follows (you must add the social frameworkto your project)

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

回答by hariszaman

your question is a bit unclear but you can use this code for publishing text and image to Fb considering you have implemented all the others methods of FB ios Api correctly

您的问题有点不清楚,但考虑到您已正确实施 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];

for further details to implement fb api you can see

有关实现 fb api 的更多详细信息,您可以查看

How to integrate Facebook into iPhone Appenter link description here

如何将 Facebook 集成到 iPhone App 中,请在此处输入链接描述

this link shows the parameters allowed while publishing a message http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/

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