2012-10-25 67 views
0

我跟隨Getting Started with the Facebook SDK for iOS v3.1將Facebook SDK添加到我的xCode項目Storyboard將Facebook SDK添加到我的xCode項目中Storyboard

我做了所有描述的步驟。

我們在Facebook SDK的示例文件夾中有一個HelloFacebookSample。它包括這樣的代碼:

- (void)viewDidLoad {  
    [super viewDidLoad]; 

    // Create Login View so that the app will be granted "status_update" permission. 
    FBLoginView *loginview = [[FBLoginView alloc] init]; 

    loginview.frame = CGRectOffset(loginview.frame, 5, 5); 
    loginview.delegate = self; 

    [self.view addSubview:loginview]; 

    [loginview sizeToFit]; 
} 

// Post Status Update button handler; will attempt to invoke the native 
// share dialog and, if that's unavailable, will post directly 
- (IBAction)postStatusUpdateClick:(UIButton *)sender { 
    // Post a status update to the user's feed via the Graph API, and display an alert view 
    // with the results or an error. 
    NSString *name = self.loggedInUser.first_name; 
    NSString *message = [NSString stringWithFormat:@"Updating status for %@ at %@", 
         name != nil ? name : @"me" , [NSDate date]]; 

    // if it is available to us, we will post using the native dialog 
    BOOL displayedNativeDialog = [FBNativeDialogs presentShareDialogModallyFrom:self 
                    initialText:nil 
                      image:nil 
                      url:nil 
                     handler:nil]; 
    if (!displayedNativeDialog) { 

     [self performPublishAction:^{ 
      // otherwise fall back on a request for permissions and a direct post 
      [FBRequestConnection startForPostStatusUpdate:message 
             completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
              [self showAlert:message result:result error:error]; 
              self.buttonPostStatus.enabled = YES; 
             }]; 

      self.buttonPostStatus.enabled = NO; 
     }]; 
    } 
} 

這樣,採樣工作正常,但是當我想有它在我自己的項目,我有這樣的問題:

它成功添加FBLoginView我self.view。但是當我Login然後想發佈的東西我只是去這個頁面:

enter image description here

+0

您是否在設置應用程序中配置了任何iOS6 Facebook帳戶?通常情況下,如果沒有配置帳戶,您將在iOS 6上收到此消息。 – rckoenes

+0

我想在模擬器上測試它。不是設備。我怎樣才能做到這一點?正如我所說的樣本爲我工作,那麼爲什麼這個作品和我自己的不是? – Ali

+0

即使在模擬器去設置和添加Facebook的帳戶,所以你可以發佈 –

回答

0

最後我發現這個問題。我需要將這些代碼添加到我的AppDelegate:

- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 
    // attempt to extract a token from the url 
    return [FBSession.activeSession handleOpenURL:url]; 
} 

- (void)applicationWillTerminate:(UIApplication *)application { 
    // FBSample logic 
    // if the app is going away, we close the session object 
    [FBSession.activeSession close]; 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application { 
    // FBSample logic 
    // We need to properly handle activation of the application with regards to SSO 
    // (e.g., returning from iOS 6.0 authorization dialog or from fast app switching). 
    [FBSession.activeSession handleDidBecomeActive]; 
} 

他們沒有在鏈接中描述。讓新用戶瞭解這些細節可能會更好。