我在自定义表格视图中有FB好友图片和名称。如何获取FB ID中的选定行并向多个朋友发送请求?

时间:2014-01-08 05:30:55

标签: ios facebook facebook-graph-api xcode5

我有单个FB ID,而且它不能进行多项选择。我有自定义表视图 在FB好友列表中。如何获取选定的行FB ID'

NSMutableArray *arryOfFBIds;
for (id<FBGraphUser> user in self.friendPickerController.selection) {

    NSMutableArray *selection=(NSMutableArray *) self.friendPickerController.selection;
     [selection addObject:user.id];


    arryOfFBIds = [[NSMutableArray alloc] init];
    for (id<FBGraphUser> user in self.friendPickerController.selection)
    {
        [arryOfFBIds addObject:user.id ];





                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject: arryOfFBIds forKey: @"SelectedFBIds"];
    [defaults synchronize];
        NSLog(@"array of fb id:%@",arryOfFBIds);
    }}




NSMutableDictionary* params2 =   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Invite to on Ensmbl", @"description", @"http://placebogames.com/", @"link",
                                 // 3. Suggest friends the user may want to request, could be game context specific?
                                 [arryOfFBIds componentsJoinedByString:@","],@"to",  nil];
NSLog(@"qwer:%@",params2);



[FBWebDialogs presentFeedDialogModallyWithSession:[FBSession activeSession] parameters:params2  handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
     NSLog(@"error===>%@,resultURL===>%@",error,resultURL);
 } ];


}

1 个答案:

答案 0 :(得分:1)

查看下载的SDK源文件(可能安装在My Documents文件夹中) - 其中一个示例源代码名为FriendPickerSample.xcodeproj

简而言之,为了显示朋友的表格视图,FB iOS使用一个名为FPViewController的特殊自定义tableview控制器类,它继承自UIViewController,但具有allowsMultipleSelection属性,如果设置为TRUE,则允许您选择几个朋友,直到你按完成按钮。

“完成”按钮将触发名为

的委托方法
- (void)facebookViewControllerDoneWasPressed:(id)sender {
   NSMutableString *text = [[NSMutableString alloc] init];

   // we pick up the users from the selection, and create a string that we use to     update the text view
   // at the bottom of the display; note that self.selection is a property inherited     from our base class
   for (id<FBGraphUser> user in self.friendPickerController.selection) {
        if ([text length]) {
           [text appendString:@", "];
       }
      [text appendString:user.name];
   }

    [self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"];     
}

只需使用示例代码并进行修改,即可为所选朋友群做任何您想做的事。