Storing accessToken in Facebook iOS SDK

I have the Facebook iOS SDK set up in my app. However, I have trouble determining when my session is finished. How to check if it's finished, and where (how) to store the access token received by the login?

I need to determine whether I have the access token or not right from the beginning so I know whether to log in again, or go forward in the app.


Are you familiar with NSUserDefaults ? It is for storing preferences for your app.

They are extremely easy to use, and probably what you are looking for. So it's just something like ..

NSUserDefaults *factoids;
NSString *whateverIDstring; // make this a property for convenience  

factoids = [NSUserDefaults standardUserDefaults];
self.whateverIDstring = [factoids stringForKey:@"storeTheStringHere"];

if ( ( whateverIDstring == Nil ) || ( [whateverIDstring isEqualToString:@""] ) )
    // it does not yet exist, so try to make a new one...
    // we already made one last time the program ran

// when you make a new one, save it in the prefs file like this...   
[factoids setObject:yourNewString forKey:@"storeTheStringHere"];
[factoids synchronize];

Hope it helps!

ONE get the preferences in to 'factoids' as in the example above

TWO decide on a name for your preference. 'storeTheStringHere' in the example.

THREE get your string 'whateverIDstring' in the example using stringForKey:

FOUR check if it is either nil or blank. if so, start fresh.

FIVE once you get the value, save it as shown!

Hope it helps!

Need Your Help

Drupal commerce add product to pending order

drupal drupal-commerce

I have already paid order in commerce (has status pending for example), but i need to add one more product to that order and pay for newly added product. Is there way to do that? If no, how can I s...

accessing unallocatted memory after changing matrix size

c math memory matrix jagged-arrays

I won't bother you with all the dry details of what is the assignment and the problem I'm trying to solve, I'll cut right to the chase.