2012-09-29 38 views
6

我想在Facebook上發佈使用openActiveSessionWithPublishPermissions,所以如果用戶沒有登錄,他需要先登錄,然後使用io6 Facebook本機對話框發佈消息。Facebook ios6 completionHandler未在登錄後調用

我發現我能夠登錄,但完成處理程序不會被調用。

另一件事我注意到,當我再次點擊登錄按鈕,然後調用與以下錯誤FBSessionStateClosedLoginFailed完成處理。

我確實參考了this post但仍然沒有找到解決我的問題的方法。

NSArray *permissions = [NSArray arrayWithObjects:@"publish_stream", nil]; 
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler: 
^(FBSession *session, FBSessionState status, NSError *error) 
{ 

    switch (status) { 

        case FBSessionStateOpen: 
         { 
          [FBNativeDialogs presentShareDialogModallyFrom:currentController initialText:nil image:nil url:nil handler:^(FBNativeDialogResult result, NSError *error) {}]; 
         } 
         break; 
        default: 
         break; 
        } 
       }]; 

回答

0

你應該要補充一點:

[FBNativeDialogs presentShareDialogModallyFrom:currentController initialText:nil 
    image:nil url:nil handler:^(FBNativeDialogResult result, NSError *error) { 
    if (result==FBNativeDialogResultCancelled) { 
    UIAlertView  *alert=[[UIAlertView alloc]initWithTitle:@"Error" 
     message:@"Sending Cancelled" delegate:self cancelButtonTitle:@"OK" 
     otherButtonTitles: nil]; 
    [alert show]; 
} else if (result==FBNativeDialogResultSucceeded) { 
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Succeed" 
    message:@"succeed" delegate:self cancelButtonTitle:@"OK" 
    otherButtonTitles: nil]; 
    [alert show]; 
}***}***]; 
5

確保您實現handleOpenUrl方法。

-(BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 

    return [[FBSession activeSession] handleOpenURL:url]; 

} 
+0

這樣做了,我已經添加了這段代碼。 – andyPaul