2013-03-21 95 views
5

我正在开发一个应用程序,该应用程序提供用户将他们的应用程序的详细信息分享到Facebook中。我有UITableview它包含作者名称列表,当你点击书名时,它会转到另一个UITableView,它显示每个TableViewCell中该作者的不同书。我可以在第二个UITableView显示列表。 我想知道如何分享作者姓名,书名和图像(第二个tableview细节)。 我显示的代码是这样的.. 所以当用户想分享的细节,他将不得不点击UIButton这是在作者UITableView的每个单元格中有。如何在Facebook墙上分享文本和图像(目标C)

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] 

; 

回答

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

去通过链接http://www.techotopia.com/index.php/An_iPhone_iOS_6_Facebook_Integration_Tutorial_using_UIActivityViewController – 2013-04-07 17:53:13

+0

我怎么能发布我的当前位置?? – 2015-03-18 08:53:08

1

你的问题是有点不清楚,但可以使用用于发布文字和图片的代码,以FB考虑您已经实现FB IOS阿比正确

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

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

+0

我想显示这是我从IPATH并拿到冠军的名字iPath的详细信息(书名,流派等)..详细信息从SQL DB获取..我想知道如何去关于它 – raptor 2013-03-22 17:50:35

+0

只是用iPath替换actionlinks中的第二个参数第三个参数是为图像,可以通过URL获取(您可以将所有图像放入Url中并通过XML访问它们),如果您没有任何托管并且您想要将静态图像发布到xcode项目到墙你必须看到Facebook的API API有一些方法,允许图像数据发布 – hariszaman 2013-03-22 18:26:02

相关问题