-->

Twitter / Fabric login button only working once

2019-01-25 11:13发布

问题:

I'm using, with success the Fabric Login button (TWTRLogInButton, https://dev.twitter.com/twitter-kit/ios-reference/twtrloginbutton).

In my Swift app I can authenticate myself, make calls and all. The only problem is that i've implemented a "Logout" button that calls Twitter.logOut().

As specified by the documentation (https://dev.twitter.com/twitter-kit/ios-reference/twitter) this deletes the local session but does not invalidate the remote session. The effect is that once I'm authenticated and then logged out, if I click the "Login" button again I'm logged-in again with the same user, effectively preventing me from switching user.

Any help?

回答1:

The logOut is a class method, did you call:

 Twitter.sharedInstance().logOut()


回答2:

The incomplete logout issue you guys are facing is actually more related to iOS persisting system accounts. TwitterKit automatically logs a user in if they were already logged in on iOS. You can workaround this behavioral in the use case of kiosk with these steps:

  1. Login to Twitter in Settings > Twitter
  2. Switch to your app and attempt to login with Twitter
  3. Disallow access to Twitter accounts when the grant access dialog comes up:

This prevents TwitterKit from accessing your system accounts and every user will have to login. Hope this helps!

(Initially Twitter.sharedInstance().logOut() destroys local session...)



回答3:

use method

[[Twitter sharedInstance] logInWithMethods:TWTRLoginMethodWebBasedForceLogin completion:{}]

Parameter TWTRLoginMethodWebBasedForceLogin

  • Presents a web view that doesn't use any cached sessions from Safari. Allows the developer to provide multi-user functionality with several Twitter accounts.


回答4:

I came across this problem as well, but it seems that this is how it behaves, Twitter "saves" the credentials on an OS level using Accounts framework. You can see this here:

go to Settings on your phone -> Twitter and you'll see the account there go into the account and "Delete Account"

once you delete the account you will find that when you launch your app and try to login to twitter now you will be asked to sign in.

Once an account is added there is no way to take out the account, (unless Twitter supports this and makes it public) The User will have to manually go into Settings -> Twitter and delete the account from there to be able to sign in to a different account.

Also i noticed that when you add another account into Twitter, trying to login you will be given a chance to login either account when using [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error)

edit: Upon further Research if the User allows the app to use "Twitter" accounts you are able to access the Accounts Framework and delete the account from there:

https://developer.apple.com/library/mac/documentation/Accounts/Reference/ACAccountStoreClassRef/index.html

Cheers!