[英]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.