2016-12-17 39 views
0

我有一个非常简单的iOS项目,我使用的Twitter /面料登录按钮用户登录到我的应用程序。推特/面料登录按钮没有像预期的那样行为

我设法让织物登录按钮工作。当用户点击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

Fabric documentation说,对于首次登录默认是要经过的Twitter应用程序(这可能是您的用户在已经登录应用程序时自动进行身份验证的原因),否则它将通过webAuth登录流程。

“强制登录流程使用Web OAuth流程将TWTRLoginMethodWebBased方法传递给相关的登录方法。”

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

所以,如果你想强制用户去通过web流量,尝试添加到您的代码:twitterLoginButton.loginMethods = [.webBased]

相关问题