0

我正在我的应用程序中实现签入功能。

我得到了参考网址

http://tylerwhitedesign.com/how-to-check-in-using-the-facebook-ios-sdk-and-graph-api

按照登录方法:

- (void) login {

permissions = [[NSArray arrayWithObjects: @"user_checkins", @"friends_checkins", @"publish_checkins", nil] retain];

[ facebook authorize:appID permissions:permissions delegate:self];
}

但在我的 facebook sdk 中:没有支持“[facebook authorize:appID permissions:permissions delegate:self];”的方法

帮我下载最新的 Facebook SDK 或为 iphone 中的签入功能提供示例代码??

4

1 回答 1

0

使用 登录用户FacebookSDK需要的不仅仅是代码块。我对您正在使用的特定构建不是很熟悉。但是离开Facebook 开发者文档,登录用户大致如下所示:

- (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 开发者的网站获取FacebookSDK。此外,您需要获得一个SCSessionStateChangedNotification特定于您的应用程序的密钥。

祝你好运!!

于 2013-01-10T10:39:01.330 回答