【问题标题】:Logout using Facebook's official iOS Tutorial使用 Facebook 官方 iOS 教程注销
【发布时间】:2012-03-04 14:07:24
【问题描述】:

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

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

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

我正在使用 iPhone 模拟器 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];
    }
}

【问题讨论】:

  • 如果您的问题已解决,请接受答案。这就是 SO 的工作原理

标签: iphone facebook logout


【解决方案1】:

这样做...

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

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

【讨论】:

  • 谢谢拉吉。我从 logoutButtonClicked 中删除了“(id)sender”。现在它完美运行了!
【解决方案2】:

如果您想在 logoutButtonClicked 函数中保留 (id)sender 参数,选择器函数“logoutButtonClicked”后面需要有一个分号,如下所示:

[logoutButton addTarget:self action:@selector(logoutButtonClicked:)

可以在 Apple 的 Selectors 文档中找到有关此主题的其他阅读材料: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocSelectors.html

【讨论】:

    猜你喜欢
    • 2012-10-29
    • 1970-01-01
    • 2015-06-19
    • 2013-03-14
    • 2011-09-07
    • 1970-01-01
    • 2011-05-19
    • 2015-08-30
    • 1970-01-01
    相关资源
    最近更新 更多