【问题标题】:Storing accessToken in Facebook iOS SDK在 Facebook iOS SDK 中存储 accessToken
【发布时间】:2011-05-19 10:40:57
【问题描述】:

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

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

【问题讨论】:

    标签: ios facebook facebook-graph-api facebook-ios-sdk facebook-access-token


    【解决方案1】:

    你熟悉 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一旦获得值,如图所示保存!

    希望对你有帮助!

    【讨论】:

    • Facebook iOS SDK 自带的 DemoApp 也能做到这一点。
    • 我在演示应用中看不到它。
    • 这确实有很大帮助,但是我不太确定如何去做。当您制作变量 padIDString 和 padFactoids 时,我感到很困惑。不过,我确信使用 NSUserDefaults。
    • @JohnJ 实际上你是对的,用户 NSUserDefaults 来保存你的登录状态是 twitter。如果我发现可能对您有帮助的东西,我会看看并报告。
    • 感谢@Rog 和@Joe Blow。希望我现在能走上正轨。
    猜你喜欢
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多