我想选择一个 friend 并向他们发送使用我的应用程序的邀请。
我使用 Graph API 的 invitable_friends
方法来获取尚未安装我的应用程序的好友列表。然后我在应用程序 UI 中呈现我的 friend 。用户选择 friend 并点击发送邀请。
这就是问题所在。
我尝试使用FBSDKAppInviteDialog
,但我无法在其内容中设置特定用户。并且选择 friend 的唯一可能是使用 facebook 对话框,而不是自定义 View 。
我尝试使用 FBSDKGameRequestDialog
。它的内容有一个属性to
来设置特定的用户,但是FBSDKGameRequestDialogDelegate
方法是不可达的。而且我不确定使用游戏请求是否是邀请 friend 使用我的应用程序的正确方式。
较旧的 Facebook SDK 提供了 [FBWebDialogs presentRequestsDialogModallyWithSession:message:title:parameters:handler:]
。这很好用。
最佳答案
我是这样使用的:
首先,您获取 FB 好友列表并将其存储在 NSMutableArray 中:
- (void) getFriendsFromFB:(NSDictionary*)parameters invitable:(BOOL) invitable {
NSString* graphPath = @"/me/friends";
if (invitable) {
graphPath = @"/me/invitable_friends";
}
FBSDKGraphRequest* request = [[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:parameters];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection * connection, id result, NSError *error){
if (error) {
NSLog(@"Facebook: error handling friend invite request at path %@: %@", graphPath, error.description);
}else{
NSLog(@"Facebook: successfully handled friend request for graph path %@",graphPath);
NSArray *friendArray = [result objectForKey:@"data"];
for (NSDictionary* friendDict in friendArray) {
FContact* contact = [[FContact alloc] initWithFaceBookID:friendDict[@"id"] name:friendDict[@"name"] avatarURL:friendDict[@"picture"][@"data"][@"url"]];
contact.hasMyGameInstalled = !invitable;
[[FStorage sharedInstance].friends addObject:contact];
}
NSLog(@"Facebook contacts received: %lu contacts",(unsigned long)friendArray.count);
if (!invitable) {
NSLog(@"Facebook: making game");
storage.currentGame = [[FGame alloc] initWithPreset];
[storage.savedGames addObject:storage.currentGame];
[[NSNotificationCenter defaultCenter] postNotificationName:@"GameInfoUpdated" object:nil];
}
}
}];
}
现在,我可以显示 FB 好友列表,让用户选择邀请谁。 当我选择了用户后,我会向他推荐一款游戏:
- (void) proposeGameTo:(FContact*) contact{
FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];
// Look at FBSDKGameRequestContent for futher optional properties
gameRequestContent.message = @"Let's play My brilliant game together";
gameRequestContent.title = @"My custom invitation";
gameRequestContent.to = @[contact.facebookID];
gameRequestContent.actionType = FBSDKGameRequestActionTypeTurn;
FBSDKGameRequestDialog* dialog = [[FBSDKGameRequestDialog alloc] init];
dialog.frictionlessRequestsEnabled = YES;
dialog.content = gameRequestContent;
dialog.delegate = self;
// Assuming self implements <FBSDKGameRequestDialogDelegate>
[dialog show];
}
关于ios - Facebook 开发工具包。邀请 friend 使用该应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29495641/