Facebook SDK 3.5.1 を使用して、Facebook を iOS アプリに統合しました。
iPhone 5 (iOS 6.1.2 脱獄なし) で実行すると、問題なくすべて正常に動作します。
父のiPhone 4(iOS 6.1.4脱獄なし)で実行すると、いくつかの問題があります。ログインボタンを押すと、アプリは「AppNameがあなたの基本情報と友達のリストにアクセスしようとしています」というアラートを表示します.OKを押しても何も起こりません(私のiPhone 5では、このアラートの後にログインします)。ログインボタンをもう一度押すと、同じアラートがポップアップ表示され、最初からやり直します。
私のエミュレータ (iOS 6.1) では、まったく同じ問題が発生します。エミュレータの設定で Facebook ログインを無効にすると、アラート ボックスの代わりにログイン フィールドを含むポップアップが表示されます。
この場合、エミュレーターは次のログを記録します: FBSDKLog: Cannot use the Facebook app or Safari to authorize, BLOCKED_OUT is not registered as a URL Scheme
これは、エミュレーターに Facebook アプリがインストールされていないために発生した可能性があることを読みました。しかし、この種のログインでも機能しません。
Facebook のこのページとまったく同じコードを使用しました: https://developers.facebook.com/ios/login-ui-control/
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.delegate = self;
// Align the button in the center horizontally
loginView.frame = CGRectMake((self.view.center.x - (loginView.frame.size.width / 2)), 150, loginView.frame.size.width, loginView.frame.size.height);
[self.view addSubview:loginView];
[loginView sizeToFit];
誰でも私を助けることができますか?
アップデート:
ログインボタンを押してアプリへのアクセスを許可した後、次のメソッドを実装しました。ユーザーがログインをキャンセルしたことが通知されます。
- (void)loginView:(FBLoginView *)loginView
handleError:(NSError *)error {
NSString *alertMessage, *alertTitle;
if (error.fberrorShouldNotifyUser) {
// If the SDK has a message for the user, surface it. This conveniently
// handles cases like password change or iOS6 app slider state.
alertTitle = @"Facebook Error";
alertMessage = error.fberrorUserMessage;
} else if (error.fberrorCategory == FBErrorCategoryAuthenticationReopenSession) {
// It is important to handle session closures since they can happen
// outside of the app. You can inspect the error for more context
// but this sample generically notifies the user.
alertTitle = @"Session Error";
alertMessage = @"Your current session is no longer valid. Please log in again.";
} else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
// The user has cancelled a login. You can inspect the error
// for more context. For this sample, we will simply ignore it.
NSLog(@"user cancelled login");
} else {
// For simplicity, this sample treats other errors blindly.
alertTitle = @"Unknown Error";
alertMessage = @"Error. Please try again later.";
NSLog(@"Unexpected error:%@", error);
}
if (alertMessage) {
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
}