我正在处理 Facebook 应用程序邀请,如果我已经登录到 Facebook,应用程序对话框会毫无问题地出现,但如果我没有登录,它不会出现,但控制会转到 didCompleteWithResults 委托(delegate),结果为 nil dict。如果可能请帮忙
-(IBAction)InviteFBFriends:(id)sender
{
if (![FBSDKAccessToken currentAccessToken])
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile",@"email", @"user_photos"] fromViewController:viewController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
} else if (result.isCancelled) {
// Handle cancellations
} else if([FBSDKAccessToken currentAccessToken]){
[self InviteFBFriends:nil];
}
}];
return;
}
//FOR SENDING INVITATIONS TO FRIENDS
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:myAppLinkURL];
FBSDKAppInviteDialog *fBSDKAppInviteDialog = [[FBSDKAppInviteDialog alloc] init];
fBSDKAppInviteDialog.delegate = self;
fBSDKAppInviteDialog.content = content;
[fBSDKAppInviteDialog show];
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results{
NSLog(@"%@",results);
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error{
NSLog(@"%@",error);
}
最佳答案
我建议按以下方式执行此方法,因为此 block 方法会发生延迟,此外您应该检查您的响应 token 而不是 currentAccessToken
-(IBAction)InviteFBFriends:(id)sender {
if (![FBSDKAccessToken currentAccessToken]) {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile",@"email", @"user_photos"] fromViewController:viewController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
} else if (result.isCancelled) {
// Handle cancellations
} else if(result.token){
[self showInvitationsToFriends];
}
}];
}
}
- (void)showInvitationsToFriends {
//FOR SENDING INVITATIONS TO FRIENDS
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:myAppLinkURL];
[FBSDKAppInviteDialog showFromViewController:self withContent:content delegate:self];
}
关于ios - 首次使用 iOS 发送 facebook 应用邀请不显示应用邀请对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37085543/