我正在关注Facebook的iOS tutorial for logging out

我将教程的代码添加到了我的委托.m文件中。运行它,当我单击注销按钮时,它崩溃。我不知道错误是什么意思。日志窗口显示:


  [S3DEngine_AppDelegate logoutButtonClicked]:无法识别的选择器已发送到实例0xb011dd0


我正在使用iPhone Simulator 5.0,XCode 4.2。
本教程中的区别在于我不使用applicationDidFinishLauchingWithOptions:。我也尝试过此功能,但这是相同的错误。

谢谢你的帮助

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    // Facebook
    // Add the logout button
    UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    logoutButton.frame = CGRectMake(40, 40, 200, 40);
    [logoutButton setTitle:@"Log Out" forState:UIControlStateNormal];
    [logoutButton addTarget:self action:@selector(logoutButtonClicked)
           forControlEvents:UIControlEventTouchUpInside];
    [self.viewController.view addSubview:logoutButton];


    // Disable idle timer
    //
    [application setIdleTimerDisabled:YES] ;

    // Configure and start the accelerometer
    //
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:kAccelerometerFrequency] ;
    [[UIAccelerometer sharedAccelerometer] setDelegate:self] ;

    // Create the view controller
    //
    [window addSubview:viewController.glView];
    [window makeKeyAndVisible];

    // Configure and start animation
    //
    viewController.glView.iAnimationInterval = kAnimationFrequency ;
    [viewController.glView startAnimation];

    // Configure ans start slpash view
    //
    CGRect frame = [[UIScreen mainScreen] bounds];
    splashView = [[UIImageView alloc] initWithFrame:frame];
    splashView.image = [UIImage imageNamed: @"Default.png"];
    [window addSubview:splashView];
    [window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    splashView.alpha = 0.0;
    [UIView commitAnimations];

    // Play default movie if any
    //
    [viewController.glView playDefaultMovieIfAny];

    facebook = [[Facebook alloc] initWithAppId:@"105441111111111" andDelegate:self];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]
        && [defaults objectForKey:@"FBExpirationDateKey"])
    {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![facebook isSessionValid])
    {
        [facebook authorize:nil];
    }

}

- (void) logoutButtonClicked:(id)sender
{
    [facebook logout];
}

- (void) fbDidLogout
{
    // Remove saved authorization information if it exists
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]) {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
}

最佳答案

像这样...

[logoutButton addTarget:self action:@selector(logoutButtonClicked:)
           forControlEvents:UIControlEventTouchUpInside];


要么

- (void) logoutButtonClicked
{
    [facebook logout];
}

关于iphone - 使用Facebook的官方iOS教程注销,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9256007/

10-13 04:46