[英]Facebook SDK. Invite friends to the app
我想选择一个或多个朋友,并将邀请发送给我的应用。 我使用Graph API的invitable_friends
方法来获取尚未安装我的应用程序的朋友列表。 然后我在应用UI中渲染我的朋友。 用户选择好友并点按以发送邀请。 这就是问题所在。 我尝试使用FBSDKAppInviteDialog
,但我无法在其内容中设置特定用户。 选择朋友的唯一可能性是使用Facebook对话框,而不是自定义视图。
我试图使用FBSDKGameRequestDialog
。 它的内容有一个属性to
设置特定的用户,但FBSDKGameRequestDialogDelegate
方法都无法访问。 我不确定使用游戏请求是邀请朋友使用我的应用程序的正确方法。
提供较旧的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];
}
最后我找到了解决问题的方法。 使用像Dmitry Timoshenko这样的代码发布, FBSDKGameRequestDialog
调用它的dealloc
,在那里它使他的_delegate
。 这就是我没有达到任何FBSDKGameRequestDialogDelegate
方法的原因。 我提出了强烈的@property
为FBSDKGameRequestDialog
,现在我收到的Facebook用户ID gameRequestDialog:didCompleteWithResults:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.