开发者

iPhone Facebook Connect logout crash after changing views

I've implemented Facebook Connect in my app just like the sample app that Facebook provides and it works well. After a user chooses to share data via Facebook they are taken to a new view and presented with the FB login dialog. When the user is done they exit the FB sharing view and return to my app's previous view. The user stays logged in as long as they don't logout - even if they exit the FB sharing view. This is good and as expected.

I'm using the same viewDidLoad method as the sample SessionViewController.m, and this is where _session is initialized:

- (void)viewDidLoad { 
    [_session resume];
    _loginButton.style = FBLoginButtonStyleWide;
}

However I noticed that if the user presses the Logout button after exiting and re-loading the FB sharing view it will throw SIGABRT or EXC_BAD_ACCESS and crash the app. The EXC_BAD_ACCESS error occurs at the [dialog show] line of the Login button's touchUpInside method:

- (void)touchUpInside {
  if (_session.isConnected) {
    [_session logout];
  } else {
    FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
    [dialog show];
  }

Even though the user is connected the touchUpInside method is seeing a disconnected session... Sometimes instead of crashing after pressing the Logout button the logout will be successful b开发者_StackOverflow社区ut the view's status text remains "Logged in as ..." and the set status/upload image buttons are not hidden. Trying to log in again throws a SIGABRT, which looks due to a nil _session.sessionKey in FBRequest.m:344:

[_params setObject:_session.sessionKey forKey:@"session_key"];

Is there something I should be retaining or doing differently across view changes?

EDIT: I found another user having this same issue on the Facebook Developer Forums: http://forum.developers.facebook.com/viewtopic.php?pid=193727#p193727

There is no solution posted but if I find one I'll update this question.


_session is nil at that point, right (that's consistent with the "always showing not connected"). Where do you initialize _session?

ETA: This is your code, which is taking the place of SessionViewController provided by Facebook Connect, right?

I can't figure out how _session could have been released, but that's what it seems like.

Adding:

You might want to change your button handler to

[_session resume];

and then do whatever you need to do in the didLogin delegate handler. That way the _session instantiates the FBLoginDialog for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜