Twitter / Fabric登录按钮的行为不符合预期

时间:2016-12-17 10:14:40

标签: ios swift twitter twitter-fabric

我有一个非常简单的iOS项目,我使用Twitter / Fabric登录按钮登录我的应用程序。

我设法让Fabric登录按钮正常工作。当用户点击Twitter登录按钮时,他们会自动进行身份验证(如果他们登录到Twitter应用程序中),否则会向用户显示Twitter登录屏幕。

我不确定为什么用户在手机上登录Twitter应用时会自动进行身份验证。

  

有没有办法使用Twitter / Fabic API打开Twitter应用程序,并要求获得授权访问我的应用程序,类似于Facebook登录,即使用户已登录Twitter应用程序。

这就是我AppDelegate的样子:

Twitter.sharedInstance().start(withConsumerKey: "someKey", consumerSecret: "someSecret")
Fabric.with([Twitter.self])

这就是我ViewController的样子:

@IBOutlet private weak var twitterLoginButton: TWTRLogInButton!

// and 
twitterLoginButton.logInCompletion = {(session, error) in
        if error != nil {
            print("ERROR: \(error)")
        } else {
            if let unwrappedSession = session {
                print(unwrappedSession.userName)
            }
        }
}

Twitter.sharedInstance().logIn { (session, error) in
        if let unwrappedSession = session {
            print("Signed in as: \(unwrappedSession.userName)")
        } else {
            print("ERROR: \(error)")
        }
}

1 个答案:

答案 0 :(得分:1)

Fabric documentation表示登录的第一个默认设置是通过Twitter应用程序(这可能就是为什么如果用户已经登录应用程序,您的用户会自动进行身份验证),否则它将通过webAuth登录流程。

"要强制登录流程以使用Web OAuth流程,请将TWTRLoginMethodWebBased方法传递给相关的登录方法。"

// If using the TWTRLoginButton
let logInButton = TWTRLogInButton() { session, error in
}
logInButton.loginMethods = [.webBased]

因此,如果您想强制用户浏览网络流程,请尝试添加代码:twitterLoginButton.loginMethods = [.webBased]