【问题标题】:How to share text and image on facebook wall (objective C)如何在 Facebook 墙上分享文字和图像(目标 C)
【发布时间】:2016-06-26 22:31:16
【问题描述】:

我正在开发一个应用程序,该应用程序允许用户将其应用程序的详细信息分享到 facebook。我有 UITableview,其中包含作者姓名列表,当您单击书名时,它会转到另一个 UITableView,它在每个 TableViewCell 中显示该作者的不同书籍。我可以在第二个 UITableView 中显示列表。 我想知道如何分享作者姓名、书名和图片(第二个表格视图详细信息)。 我正在显示执行此操作的代码.. 所以当用户想要分享细节时,他必须点击作者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 objective-c iphone xcode uitableview


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    您的问题有点不清楚,但考虑到您已正确实现 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 Appenter link description here

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

    【讨论】:

    • 我想显示从 iPath 获得的标题名称和 iPath 的详细信息(书名、流派等).. 详细信息是从 sql db 中获取的.. 我想知道如何去做吧
    • 只需将 actionlinks 中的第二个参数替换为 iPath,第三个参数用于可以通过 URL 获取的图像(您可以将所有图像放在 Urls 中并通过 XML 访问它们)如果您没有任何托管,并且您想将 xcode 项目中的静态图像发布到墙上,您必须查看 Facebook api,那里有一些方法可以发布图像数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多