0

我正在关注iOS v3.1 的 Facebook SDK 入门,以将 Facebook SDK 添加到我的 xCode 项目中Storyboard

我做了那里描述的所有步骤。

我们在 Facebook SDK 的 Sample 文件夹中有一个 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想发布一些东西时,我就去这个页面:

在此处输入图像描述

4

1 回答 1

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];
}

链接中没有描述它们。让新用户知道这些细节可能会更好。

于 2012-10-25T12:19:03.747 回答