Search code examples
iphonefacebookcachingtokenfacebook-ios-sdk

Managing own token cache crashing ios


I have followed the steps to manage my own token cache when a user logs in through Facebook on my app, however it always crashes when the login button is pressed. It calls:

NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:self.tokenFilePath];

and then crashes. If I change the initialisation of

_tokenFilePath = [self filePath];

to

self.tokenFilePath = [self filePath];

then it doesn't crash, but then sometimes the login button has to be pressed multiple times before it logs in. How can I fix this?

Thank you.


Solution

  • If you are not using ARC there is going to be a retain difference.

    self.tokenFilePath calls a setter and that setter is increasing the retain count of filePath.

    Without ARC assigning directly to an ivar does not increase the retain count. Use:

    _tokenFilePath = [[self filePath] retain];
    

    With ARC the direct assignment increases the retain count.