ios - 首次使用 iOS 发送 facebook 应用邀请不显示应用邀请对话框

标签 ios objective-c facebook

我正在处理 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/

相关文章:

ios - iphone 5 响应修复导航栏故障?

objective-c - 在哪里声明枚举结构?

ios - 从 Crashlytics 3.0.0 开始,实现用户提示是应用程序的责任

objective-c - Target-Action 设计模式是否在 ARC 下变成了坏习惯?

android - fragment 是否默认使用 savedInstanceState 保存?

android - Facebook Messenger 如何绘制聊天头? (安卓)

android - 添加到手机主屏幕

iphone - 如何为 iPhone 创建一个带有黑色渐变的 UIButton?

ios - 如何显示我的 TableView Controller 的 UILabel 文本?

php - 使用 Facebook PHP SDK 在单个请求中检索多个字段