[英]Facebook SDK. Invite friends to the app
I want to choose one of more friends and send them an invite to my app. 我想选择一个或多个朋友,并将邀请发送给我的应用。 I use invitable_friends
method of Graph API to get a list of friends, who didn't install my app yet. 我使用Graph API的invitable_friends
方法来获取尚未安装我的应用程序的朋友列表。 Then I render my friends in the app UI. 然后我在应用UI中渲染我的朋友。 User choose friends and tap to send invitations. 用户选择好友并点按以发送邀请。 And here's the problem. 这就是问题所在。 I tried to use FBSDKAppInviteDialog
, but I couldn't set specific users in its content. 我尝试使用FBSDKAppInviteDialog
,但我无法在其内容中设置特定用户。 And the only one possibility to choose friends is to use facebook dialog, not custom view. 选择朋友的唯一可能性是使用Facebook对话框,而不是自定义视图。
I tried to use FBSDKGameRequestDialog
. 我试图使用FBSDKGameRequestDialog
。 Its content has a property to
to set specific users, but the FBSDKGameRequestDialogDelegate
methods are unreachable. 它的内容有一个属性to
设置特定的用户,但FBSDKGameRequestDialogDelegate
方法都无法访问。 And I'm not sure that using game request is the right way to invite friends to use my app. 我不确定使用游戏请求是邀请朋友使用我的应用程序的正确方法。
Older Facebook SDK provided [FBWebDialogs presentRequestsDialogModallyWithSession:message:title:parameters:handler:]
. 提供较旧的Facebook SDK [FBWebDialogs presentRequestsDialogModallyWithSession:message:title:parameters:handler:]
。 And this worked fine. 这很好用。
I use it this way: 我用这种方式:
First, you get list of FB friends and store it in NSMutableArray: 首先,您获取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];
}
}
}];
}
Now, I can display list of FB friends and let user choose whom to invite. 现在,我可以显示FB好友列表,让用户选择邀请对象。 And when I have user selected, I'd propose a game to him: 当我选择用户时,我会向他提出一个游戏:
- (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];
}
Finally I have found a solution of my problem. 最后我找到了解决问题的方法。 Using code like Dmitry Timoshenko has posted, FBSDKGameRequestDialog
calls its dealloc
, where it nilify his _delegate
. 使用像Dmitry Timoshenko这样的代码发布, FBSDKGameRequestDialog
调用它的dealloc
,在那里它使他的_delegate
。 That's why I didn't reach any FBSDKGameRequestDialogDelegate
methods. 这就是我没有达到任何FBSDKGameRequestDialogDelegate
方法的原因。 I made a strong @property
for FBSDKGameRequestDialog
and now I receive facebook user ids in gameRequestDialog:didCompleteWithResults:
. 我提出了强烈的@property
为FBSDKGameRequestDialog
,现在我收到的Facebook用户ID gameRequestDialog:didCompleteWithResults:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.