How to make User logout from twitter fabric ios

≯℡__Kan透↙ 提交于 2019-11-29 10:05:04
SeanCAtkinson

UPDATE: May 2016 - Framework has changed so this answer is no longer relevant.

See this answer: https://stackoverflow.com/a/35765833/940709 and this answer: https://stackoverflow.com/a/30916904/940709 instead.

[[[Twitter sharedInstance] sessionStore] logOutUserID:USERID];

this was a problem with NSCookie from Foundation framework And i slove this issues with help of below code

NSURL *url = [NSURL URLWithString:@"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
Purushottam Sain

You need to use below code

[[[Twitter sharedInstance] sessionStore] logOutUserID:USERID];

Provide user id of the user you want to logout.

dory daniel

This is the best simple answer for Swift 3:

let store = Twitter.sharedInstance().sessionStore
        if let userID = store.session()?.userID {
            store.logOutUserID(userID)
        }

or you can use Naeem's answer but add () after store.session

Naeem

Logout Code From Twitter Docs:

Objective-C

TWTRSessionStore *store = [[Twitter sharedInstance] sessionStore];
NSString *userID = store.session.userID;

[store logOutUserID:userID];

Swift

let store = Twitter.sharedInstance().sessionStore

if let userID = store.session()?.userID {
  store.logOutUserID(userID)
}

For Swift try this,

/**
 *  Deletes the local Twitter user session from this app. This will not remove the system Twitter account nor make a network request to invalidate the session.
 *
 *  @param userID ID of the user to log out
 */
Twitter.sharedInstance().sessionStore.logOutUserID(userId)

First make sure some user is signed in, then perform logout.

NSString *signedInUserID = [TWTRAPIClient clientWithCurrentUser].userID;
if (signedInUserID) {
   [[Twitter sharedInstance].sessionStore logoutUserID:signedInUserID];
}

While login mention method as webBasedForceLogin, so that it will not create entry into Safari Cache.

private func twitterLogin() {
    Twitter.sharedInstance().logIn(withMethods: .webBasedForceLogin, completion: { (session, error) in
        if let error = error {
            print(error.localizedDescription)
        }

        guard let session = session else {
            return
        }

        print("success! Welcome \(session.userName).")
        self.twitterButton.setTitle("TWITTER LOGOUT", for: .normal)
    })
}

private func twitterLogout() {
    let sessionStore = Twitter.sharedInstance().sessionStore
    if let userID = sessionStore.session()?.userID {
        sessionStore.logOutUserID(userID)
    }

    twitterButton.setTitle("TWITTER LOGIN", for: .normal)
}
M Singh Karnawat

Use below:

[TWTRSessionStore logout]

Deprecated:

[Twitter logOut] 

is deprecated.

Users are encouraged to call - [TWTRSessionStore logout] instead of calling this method on the Twitter instance directly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!