2014-07-15 51 views
5

我想使用他們的iOS遊戲教程中的代碼分享到Facebook。該對話框彈出,我指定的圖像和文本存在,但當我點擊「發送」加載欄出現,不加載,然後我被重定向到我的應用程序。沒有錯誤被打印到控制檯,應用程序不會崩潰。iOS未能發佈在Facebook上,沒有記錄錯誤

當我在Facebook上以檢查消息已經發布,我得到如下:。

「哎呀呀,出事了發佈您的狀態的問題。我們已經記錄的錯誤,並期待進去。」

我在以前的應用程序中使用過這段代碼,它工作得很好。我已經在plist中更新了Facebook ID,Facebook顯示名稱和URL Scheme。

下面是代碼:

FacebookHandler類(從Facebook教程派生)

#import "FacebookHandler.h" 

@implementation FacebookHandler 

+ (void) Facebook_CreateNewSession 
{ 
    // initialize Facebook 
    FBSession* session = [[FBSession alloc] init]; 
    [FBSession setActiveSession: session]; 
} 

+ (void) Facebook_Login 
{ 
    NSArray *permissions = [[NSArray alloc] initWithObjects: 
         @"email", 
         nil]; 

// Attempt to open the session. If the session is not open, show the user the Facebook login UX 
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true completionHandler:^(FBSession *session, FBSessionState status, NSError *error) 
{ 
    // Did something go wrong during login? I.e. did the user cancel? 
    if (status == FBSessionStateClosedLoginFailed || status == FBSessionStateCreatedOpening) { 

     // If so, just send them round the loop again 
     [[FBSession activeSession] closeAndClearTokenInformation]; 
     [FBSession setActiveSession:nil]; 
     [self Facebook_CreateNewSession]; 
    } 
    else 
    { 
    }     
}]; 
} 

+ (void) Facebook_PostToNewsFeedWithTitle:(NSString*)title withCaption:(NSString*)caption withDescription:(NSString*)description withLink:(NSString*)link withPictureURL:(NSString*)picURL 
{ 

// check if user is logged in 
if ([FBSession activeSession] == nil) 
{ 
    [FacebookHandler Facebook_CreateNewSession]; 
    [FacebookHandler Facebook_Login]; 
} 


// This function will invoke the Feed Dialog to post to a user's Timeline and News Feed 
// It will attemnt to use the Facebook Native Share dialog 
// If that's not supported we'll fall back to the web based dialog. 

NSString *linkURL = link; 
NSString *pictureURL = picURL; 

// Prepare the native share dialog parameters 
FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init]; 
shareParams.link = [NSURL URLWithString:linkURL]; 
shareParams.name = title; 
shareParams.caption= caption; 
shareParams.picture= [NSURL URLWithString:pictureURL]; 
shareParams.description = description; 

if ([FBDialogs canPresentShareDialogWithParams:shareParams]){ 

    [FBDialogs presentShareDialogWithParams:shareParams 
           clientState:nil 
            handler:^(FBAppCall *call, NSDictionary *results, NSError *error) { 
             if(error) { 
              NSLog(@"Error publishing story."); 
             } else if (results[@"completionGesture"] && [results[@"completionGesture"] isEqualToString:@"cancel"]) { 
              NSLog(@"User canceled story publishing."); 
             } else { 
              NSLog(@"Story published."); 
             } 
            }]; 

}else { 

    // Prepare the web dialog parameters 
    NSDictionary *params = @{ 
          @"name" : shareParams.name, 
          @"caption" : shareParams.caption, 
          @"description" : shareParams.description, 
          @"picture" : pictureURL, 
          @"link" : linkURL 
          }; 

    // Invoke the dialog 
    [FBWebDialogs presentFeedDialogModallyWithSession:nil 
              parameters:params 
               handler: 
    ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
     if (error) { 
      NSLog(@"Error publishing story."); 
     } else { 
      if (result == FBWebDialogResultDialogNotCompleted) { 
       NSLog(@"User canceled story publishing."); 
      } else { 
       NSLog(@"Story published."); 
      } 
     }}]; 
} 
} 
@end 

我的呼叫

[FacebookHandler Facebook_PostToNewsFeedWithTitle:title withCaption:caption withDescription:description withLink:link withPictureURL:picURL]; 

UPDATE

這似乎是Facebook應用程序的問題。在卸載Facebook的設備上試用時,系統會要求我登錄併成功發佈。但是,如果安裝了Facebook,它不會發布。

+0

我也面臨這個問題,而它在模擬器中正常工作。 –

+0

目前爲止的解決方案?我也有同樣的問題。 –

回答

0

我通過手動修復在plist文件中輸入「URL types」鍵。 不要複製粘貼從另一個plist文件的plist值 - 這是蘋果的錯誤!

相關問題