本文介绍了我该如何储存&访问Twitter Fabric登录会话(iOS / Swift)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用这个Twitter Fabric代码通过我的应用程序登录Twitter:

I'm able to log in to Twitter through my app using this Twitter Fabric code:

 let logInButton = TWTRLogInButton(logInCompletion: {
        (session: TWTRSession!, error: NSError!) in
             // play with Twitter session
             if (session != nil) {
                 println("signed in as \(session.userName)");
                 self.TWUsernameLabel.text = "Logged in as @" + session.userName
        } else {
            println("error: \(error.localizedDescription)");
        }
    })

当我点击登录按钮,它提示我批准登录,然后登录,或者它知道我已经批准了登录,它会让我登录。这就像一个魅力,并花了十分钟设置。很棒。

When I click the login button, it prompts me to approve the login and then logs me in, or it knows I already approved the login and it logs me in. This works like a charm and took all of ten minutes to set up. Amazing.

我已经有一个基于电子邮件的登录来访问该应用程序。我想将用户登录的Twitter帐户存储在同一个数据库中,因此当用户使用他们的电子邮件登录时,我已经知道他们的Twitter(如果他们之前已经登录)并且他们不需要再次登录。我进行电子邮件登录的原因是因为Twitter是我的应用程序中的一个重要功能,但不是总要求。

I already have an email-based login to access the app. I'd like to store a user's logged in Twitter account in that same database, so when a user logs in with their email, I already know their Twitter (if they have logged in before) and they don't need to log in again. The reason I do the email login is because Twitter is an important feature in my app, but not a total requirement.

问题是我不知道如何访问 session 在点击按钮之外, logInCompletion 触发,我不知道在初始时要存储哪些变量登录/检查使用该应用程序。

The issue is that I have no idea how to access session outside of when the button is clicked and logInCompletion fires, and I don't know what variables to store upon initial login/check upon using the app.

我已经多次阅读Twitter Fabric文档,但它不是用swift编写的,所以它非常令人困惑。有任何想法吗?谢谢

I've read through the Twitter Fabric documentation numerous times, but it isn't written in swift, so it's pretty confusing. Any ideas? Thanks

推荐答案

如果当前有活动会话,您应该可以像文档中所说的那样访问它

If there is currently an active session you should be able to access it just like the docs say to

Twitter.sharedInstance().session() 

如果用户未登录,则该方法将返回nil。如果您想知道某人是否已经过身份验证,请检查该方法是否返回值。

If the user isn't logged in that method will return nil. If you want to know if someone is already authenticated just check to see if that method returns a value or not.

这篇关于我该如何储存&访问Twitter Fabric登录会话(iOS / Swift)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 20:06