2016-05-07 159 views
0

我正在使用Facebook應用程序邀請,如果我已經登錄到Facebook,應用程序對話框出現沒有任何問題,但如果我沒有登錄在它不是,但控制去無didCompleteWithResults代表無結果字典。請幫助如果可能的話發送facebook使用iOS的應用程序邀請不會顯示應用程序邀請對話框

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

} 

回答

1

我會建議進行這種方法爲以下,因爲有延遲發生此塊的方法,除了你應該檢查你的響應令牌,而不是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]; 
} 
+0

沒有工作。不知道爲什麼會發生這種情況,因爲控制權轉移到[fBSDKAppInviteDialog show];之後沒有顯示didCompleteWithResults方法被調用的對話框。 – user3921894

+0

但是,如果你已經登錄,你可以看到對話框視圖? – Mortgy

+0

像你必須按登錄按鈕2次才能夠獲得對話框顯示? – Mortgy

相關問題