在Facebook iOS SDK中存储accessToken

nic*_*ljs 2 facebook facebook-graph-api ios facebook-ios-sdk facebook-access-token

我在我的应用程序中设置了Facebook iOS SDK.但是,我无法确定会话何时结束.如何检查它是否已完成,以及在何处(如何)存储登录收到的访问令牌?

我需要从一开始就确定我是否拥有访问令牌,因此我知道是否要再次登录,或者在应用程序中继续.

Fat*_*tie 7

你熟悉NSUserDefaults吗?它用于存储您的应用的首选项.

它们非常易于使用,可能正是您所寻找的.所以它就像......

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...
else
    // 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];
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!

ONE将偏好设置为'factoids',如上例所示

两个人根据您的偏好决定名称.示例中的'storeTheStringHere'.

三个使用stringForKey在示例中获取字符串'whateverIDstring':

检查是否为空或空白.如果是这样,重新开始.

,一旦你得到的价值,将其保存如图所示!

希望能帮助到你!