简体   繁体   English

在Facebook iOS SDK中存储accessToken

[英]Storing accessToken in Facebook iOS SDK

I have the Facebook iOS SDK set up in my app. 我在我的应用中设置了Facebook iOS SDK 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 ? 您熟悉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...
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];

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. 在示例中为“ storeTheStringHere”。

THREE get your string 'whateverIDstring' in the example using stringForKey: 使用stringForKey让你的字符串“whateverIDstring”的例子:

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! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM