2

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

我需要从一开始就确定我是否拥有访问令牌,以便我知道是再次登录还是在应用程序中继续前进。

4

1 回答 1

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];

希望能帮助到你!

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

两个根据您的喜好决定一个名称。示例中的“storeTheStringHere”。

在使用 stringForKey 的示例中获取您的字符串“whateverIDstring”:

检查它是 nil 还是空白。如果是这样,重新开始。

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

希望能帮助到你!

于 2010-12-02T22:52:01.647 回答