Facebook sdk iOS注销错误

时间:2012-08-09 19:36:42

标签: objective-c xcode facebook

我目前正在使用新的Facebook SDK,我有一个非常奇怪的问题。我有一个名为FacebookExplorerTableViewController的viewcontroller,在我的viewdidload中我有以下代码:

if(appDelegate.session.isOpen)
    {
        [self receiveAlbums];
    }
    else 
    {
        appDelegate.session = [[FBSession alloc] init];

        appDelegate.session = [FBSession sessionOpenWithPermissions:nil completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
            NSLog(@"opened session");
            if(!error) [self receiveAlbums];
            else NSLog(@"error: %@",error);
        }];
}

当我运行它时,一切都很好。但是,我有另一个viewController,名为SharingSettingsTableViewController,我可以选择注销:

[appDelegate.session closeAndClearTokenInformation];

当我尝试注销时,我遇到了xCode崩溃:

2012-08-09 21:29:19.683 My Albums[2197:17903] opened session
2012-08-09 21:29:19.684 My Albums[2197:17903] requesting albums
2012-08-09 21:29:19.695 My Albums[2197:17903] access token: (null)
2012-08-09 21:29:19.697 My Albums[2197:17903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x1b6d022 0x1f56cd6 0x1aac7db 0x1ac4e86 0x757a5 0x754f4 0xa17e2 0x9ef39 0x676f9 0x92c3f1 0x1b6ee99 0x55514e 0x5550e6 0x5fbade 0x5fbfa7 0x5fb266 0x57a3c0 0x57a5e6 0x560dc4 0x554634 0x232eef5 0x1b41195 0x1aa5ff2 0x1aa48da 0x1aa3d84 0x1aa3c9b 0x232d7d8 0x232d88a 0x552626 0x21ed 0x2155)
terminate called throwing an exception

似乎再次运行我的完成块!控制台中的“请求相册”来自对receiveAlbums的调用。

为什么这个完成块再次运行?当我进入Settings视图控制器时,我已经取消分配了FacebookExplorerTableViewController!怎么能运行,我怎么能摆脱错误? :)

提前致谢!

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题。我的问题是将[FBSession activeSession].accessToken传递给NSDictionary。最简单的解决方案是传递[NSString stringWithFormat:@"%@", [FBSession activeSession].accessToken]而不是直接使用[FBSession activeSession].accessToken