簡體   English   中英

使用iOS發送Facebook應用邀請不會首次顯示應用邀請對話框

[英]Sending facebook App invitation using iOS doesn't show app invite dialog for the first time

我正在處理Facebook App邀請,如果我已經登錄到Facebook,則出現“應用程序”對話框沒有任何問題,但是如果我沒有登錄,則沒有,但是控件轉到具有零結果指令的didCompleteWithResults委托。 請幫助

-(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);

}

我建議按以下方式執行此方法,因為此塊方法會發生延遲,此外您還應檢查響應令牌而不是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]; 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM