Facebook iOS SDK 3.0 - save and reload .selection in FBFriendPickerViewController

FBFriendPickerViewController looks pretty simple. However, it may not be intended for the scenario that I want.

Essentially, I want to keep a list of friends that the user selects on disk. On subsequent application launches, I want to show FBFriendPickerViewController with these "saved" friends as already selected.

Since the .selection attribute is read-only, I'm not sure how to load a new instance of FBFriendPickerViewController with a subset of friends already selected.

+4
source share
1 answer

Finally, I found a solution.

I have an NSDictionary dict whose key is the facebook user id and the value is the name. Roughly speaking, this is the code:

 NSMutableArray *results = [[NSMutableArray alloc] init]; for (id key in dict) { NSString *name = [dict valueForKey:key]; id<FBGraphUser> user = (id<FBGraphUser>)[FBGraphObject graphObject]; user.id = key; [user setName:name]; // This is not mandatory if (user) { NSLog(@"adding user: %@", user.name); [results addObject:user]; } } // And finally set the selection property friendPickerController.selection = results; 

UPDATE: it doesn't seem to be working properly ... you will see that the friends checked correctly, but when you go to parse .selection , when you finish the selection, you will only get the friends that you checked in the user interface, not predefined ...

UPDATE 2: it seems that everything is fine if you fill in all the fields listed in the FBGraphUser.h header file

+1
source

Source: https://habr.com/ru/post/1432196/


All Articles