0

Facebook SDK for iOS v3.1のスタートガイドに従って、FacebookSDKをxCodeプロジェクトに追加しStoryboardます。

私はそこで説明されているすべてのステップを実行しました。

FacebookSDKの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 に答える