How to make User logout from twitter fabric ios

后端 未结 9 1237
慢半拍i
慢半拍i 2020-12-20 16:28

I have made a basic app using Twitter\'s fabric that allows user to tweet within my app and Provide Login With Twitter.Every things works a I Wanted.

相关标签:
9条回答
  • 2020-12-20 16:41

    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

    0 讨论(0)
  • 2020-12-20 16:44

    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)
    }
    
    0 讨论(0)
  • 2020-12-20 16:47

    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)
    }
    
    0 讨论(0)
  • 2020-12-20 16:51

    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];
    }
    
    0 讨论(0)
  • 2020-12-20 16:54

    You need to use below code

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

    Provide user id of the user you want to logout.

    0 讨论(0)
  • 2020-12-20 16:55

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

    NSString *signedInUserID = [TWTRAPIClient clientWithCurrentUser].userID;
    if (signedInUserID) {
       [[Twitter sharedInstance].sessionStore logoutUserID:signedInUserID];
    }
    
    0 讨论(0)
提交回复
热议问题