を使用してユーザーにサインインするにはFacebookSDK
、コードのブロック以上のものが必要です。私はあなたが使用している特定のビルドにあまり精通していません。しかし、Facebook Developer Documentationから離れると、ユーザーのログインはおおよそ次のようになります。
- (void)createAndPresentLoginView
{
if (self.loginViewController == nil) {
self.loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController"
bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.loginViewController];
self.window.rootViewController = self.navController;
}
}
- (void)showLoginView
{
if (self.loginViewController == nil) {
[self createAndPresentLoginView];
} else {
[self.loginViewController loginFailed];
}
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error
{
// FBSample logic
// Any time the session is closed, we want to display the login controller (the user
// cannot use the application unless they are logged in to Facebook). When the session
// is opened successfully, hide the login controller and show the main UI.
switch (state) {
case FBSessionStateOpen: {
// For gaining current location
// [self.mainViewController startLocationManager];
if (self.loginViewController != nil) {
[self initializeTabBarController];
[self.navController pushViewController:self.tabBarController animated:NO];
self.loginViewController = nil;
}
// FBSample logic
// Pre-fetch and cache the friends for the friend picker as soon as possible to improve
// responsiveness when the user tags their friends.
FBCacheDescriptor *cacheDescriptor = [FBFriendPickerViewController cacheDescriptor];
[cacheDescriptor prefetchAndCacheForSession:session];
}
break;
case FBSessionStateClosed: {
// FBSample logic
// Once the user has logged out, we want them to be looking at the root view.
UIViewController *topViewController = [self.navController topViewController];
UIViewController *modalViewController = [topViewController presentedViewController];
if (modalViewController != nil) {
[topViewController dismissViewControllerAnimated:NO completion:nil];
}
[self.navController popToRootViewControllerAnimated:NO];
[FBSession.activeSession closeAndClearTokenInformation];
[self performSelector:@selector(showLoginView)
withObject:nil
afterDelay:0.5f];
}
break;
case FBSessionStateClosedLoginFailed: {
// if the token goes invalid we want to switch right back to
// the login view, however we do it with a slight delay in order to
// account for a race between this and the login view dissappearing
// a moment before
[self performSelector:@selector(showLoginView)
withObject:nil
afterDelay:0.5f];
}
break;
default:
break;
}
[[NSNotificationCenter defaultCenter] postNotificationName:SCSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error: %@",
[ShindyAppDelegate FBErrorCodeDescription:error.code]]
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
ただし、 Facebook開発者のWebサイトからFacebookSDKを取得する必要があります。SCSessionStateChangedNotification
また、アプリケーションに固有のと呼ばれるキーを取得する必要があります。
頑張ってください!