Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook FBConnect fbDialogLogin method in Facebook.m hits EXC_BAD_ACCESS on FBSessionDelegate object _sessionDelegate


using facebook-facebook-ios-sdk-cf1c2c3, the _sessionDelegate object is being deallocated before my app is moved to the background.

This means when the app comes to the foreground after the authentication/authorization callback, this method in Facebook.m hits causes a EXC_BAD_ACCESS:

- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate

The offending line in that method being this one:

  if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogin)]) {
    [_sessionDelegate fbDidLogin];
  }

I think this is because in Facebook.h, _sessionDelegate is being assigned not retained. Therefore at some point it is deallocated:

@property(nonatomic, assign) id<FBSessionDelegate> sessionDelegate;

Changing it to retain appears to resolve the problem:

@property(nonatomic, retain) id<FBSessionDelegate> sessionDelegate;

Seems like too obvious a thing to me. Therefore I must be missing something!

Any ideas?

Many thanks, xj

like image 383
Max MacLeod Avatar asked May 10 '11 09:05

Max MacLeod


1 Answers

Changing the delegate to a retain method in this case is probably a more stable solution than anything else. However somewhere your delegate is being released before you want it to be released and you may need to look into what would cause it to be released early. However if you do this make sure you edit the Facebook.m dealloc() method to release your delegate

like image 126
davydotcom Avatar answered Nov 02 '22 01:11

davydotcom