我目前有以下代码,可以选择一个随机的 Facebook 朋友并发布到他们的墙上。我希望能够从所有朋友中进行选择(而不是随机选择一个)并发布到他们的墙上。如果有人可以帮助我使用以下代码,那就太好了:)
case gkAPIFriendsForDialogFeed:
{
NSArray *resultData = [result objectForKey: @"data"];
// Check that the user has friends
if ([resultData count] > 0) {
// Pick a random friend to post the feed to
int randomNumber = arc4random() % [resultData count];
[self apiDialogFeedFriend:
[[resultData objectAtIndex: randomNumber] objectForKey: @"id"]];
} else {
[self showMessage:@"You do not have any friends to post to."];
}
break;
}
此代码选择所有朋友,但不会发布到他们的墙上,而是向他们发送通知:
case gkAPIGetAppUsersFriendsUsing:
{
NSMutableArray *friendsWithApp = [[NSMutableArray alloc] initWithCapacity:1];
// Many results
if ([result isKindOfClass:[NSArray class]]) {
[friendsWithApp addObjectsFromArray:result];
} else if ([result isKindOfClass:[NSDecimalNumber class]]) {
[friendsWithApp addObject: [result stringValue]];
}
if ([friendsWithApp count] > 0) {
[self apiDialogRequestsSendToUsers:friendsWithApp];
} else {
[self showMessage:@"None of your friends are using Whatto."];
}
[friendsWithApp release];
break;
}