【发布时间】:2011-05-19 10:40:57
【问题描述】:
我在我的应用程序中设置了Facebook iOS SDK。但是,我无法确定我的会话何时结束。如何检查是否完成,以及在哪里(如何)存储登录收到的访问令牌?
我需要从一开始就确定我是否拥有访问令牌,以便我知道是重新登录还是在应用程序中继续。
【问题讨论】:
标签: ios facebook facebook-graph-api facebook-ios-sdk facebook-access-token
我在我的应用程序中设置了Facebook iOS SDK。但是,我无法确定我的会话何时结束。如何检查是否完成,以及在哪里(如何)存储登录收到的访问令牌?
我需要从一开始就确定我是否拥有访问令牌,以便我知道是重新登录还是在应用程序中继续。
【问题讨论】:
标签: ios facebook facebook-graph-api facebook-ios-sdk facebook-access-token
你熟悉 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];
希望对您有所帮助!
ONE 将偏好设置为“factoids”,如上例所示
两个根据您的喜好决定一个名称。示例中的“storeTheStringHere”。
THREE 在示例中使用 stringForKey 获取您的字符串 'whateverIDstring':
FOUR 检查它是 nil 还是空白。如果是这样,请重新开始。
FIVE一旦获得值,如图所示保存!
希望对你有帮助!
【讨论】: