Reputation: 23
I've been working with Facebook to make a multiplayer game. I want to allow the player to be able to invite his friends from Facebook to play in a match, so I use FBFriendPickerViewController for this. However, I want to limit the number of selected friends to a minimun of 1 player and a maximun of 4.
The problem is that there's no obvious way to do this, or at least none mentioned in the Developer documents at Facebook. I tried to prevent this inside
- (void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker
but as the attribute NSArray *selection is readonly, it can't be done. I had also thought of warning the user after he had selected the friends and clicked the 'Done'button, but it's kind of lame allowing him to choose 100 friends and after that warning him about the 4 players max limit.
Does anyone have any idea how to do this? Or will I have to implement a full FBFriendPickerViewController from scratch?
Thanks! :D
Upvotes: 2
Views: 527
Reputation: 3032
Replying a bit late, but I was just looking for a solution to this issue, and I went with something that I found to be a bit cleaner than the other solutions listed:
- (void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker {
if ([friendPicker.selection count] > 3) {
friendPicker.doneButton.enabled = NO;
[[[UIAlertView alloc] initWithTitle:@"Too many selections"
message:@"You may only select up to 3 friends."
delegate:nil
cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
} else {
friendPicker.doneButton.enabled = YES;
}
}
I inform the user that they have exceeded the max (via UIAlertView), then I disable the Done button. When the count comes back down to a valid number, I re-enable the Done button.
Upvotes: 0
Reputation: 1473
just removing the friend picker isn't the solution! but this is! i got it , after struggling for quite a few times.
solution was simpler than i imagined.
you friendPickerController
is a tableView so we can set userInteractionEnabled
property to NO
.
- (void)friendPickerViewControllerSelectionDidChange:
(FBFriendPickerViewController *)friendPicker
{
if ([friendPicker.selection count] <=3)
{
self.friendPickerController.tableView.userInteractionEnabled=YES;
}
if ([friendPicker.selection count] >=3)
{
UIAlertView *maxFriendsAlert =
[[UIAlertView alloc] initWithTitle:@"Max number of friends selected."
message:@"no more friends can be selected,"
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:@"Buy more friends",nil];
[maxFriendsAlert show];
maxFriendsAlert.tag=1;
// disable friends selection
self.friendPickerController.tableView.userInteractionEnabled=NO;
}
Upvotes: 0
Reputation: 5523
One work around could be showing a label/message on the picker letting the user know they can pick up to 4 friends. Then after picking four you dismiss the view controller? Then you could add code like this:
- (void)friendPickerViewControllerSelectionDidChange:
(FBFriendPickerViewController *)friendPicker
{
if ([friendPicker.selection count] > 3) {
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:@""
message:@"Max number of friends selected."
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self dismissModalViewControllerAnimated:YES];
}
You may be looking for a better experience, for example to give users a chance to edit from their maximum list. In that case you can get the source code from GitHub tableView:didSelectRowAtIndexPath: and tableView:didDeselectRowAtIndexPath: delegate methods in the FBGraphObjectTableSelection class. Looks like you would likely add a new "maxSelection" property and key off that.
Upvotes: 1
Reputation: 6394
Previous SDK was HTML based and was hosted on facebook but SDK 3.x is native iOS code with open source.
You can modify Facebook SDK. It is licensed under Apache license and add limit for friends you allow to invite.
Upvotes: 0