在 Facebook iOS SDK 中存储 accessToken

发布于 2024-10-05 22:24:31 字数 206 浏览 3 评论 0原文

我在我的应用程序中设置了 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2024-10-12 22:24:31

你熟悉 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 或空白。如果是这样,请重新开始。

一旦获得该值,请按所示保存!

希望有帮助!

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...
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.

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文