How to get completely logout from FHSTwitterEngine

2020-03-13 08:48发布

FHSTwitterEngine *engine = [FHSTwitterEngine sharedEngine];
[engine clearAccessToken];

I tried above code but when I try to login again, textfields doesn't apear in presentModalViewController, it shows Authorize app button.

There is another method, [engine clearConsumer]; which results Select and Copy the PIN in presentModalViewController

2条回答
Lonely孤独者°
2楼-- · 2020-03-13 09:08

I believe cookies still exists, that's the major issue with most of the twitter APIs on iOS.

This is how you can check for all cookies, put a check in between to clear only twitter cookies where you are performing a logout operation on twitter:

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *each in cookieStorage.cookies) {
       // put a check here to clear cookie url which starts with twitter and then delete it
         [cookieStorage deleteCookie:each];
    }

Hope it helps.

Regards,

Reno Jones

查看更多
Juvenile、少年°
3楼-- · 2020-03-13 09:21

Add below method in FHSTwitterEngine.h and m file.

- (void)logout
{
  NSLog(@"Logged out from twitter");

  //These is FHSTwitterEngine class method which clears accesstoken
  [self clearAccessToken]; 

  //clear cache of twitter from NSHTTPCookieStorage
  NSHTTPCookie *cookie;
  NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  for (cookie in [storage cookies])
  {
    NSString* domainName = [cookie domain];
    NSRange domainRange = [domainName rangeOfString:@"twitter"];
    if(domainRange.length > 0)
    {
        [storage deleteCookie:cookie];
    }
  }
}

EDIT : Use these method like these :

[[FHSTwitterEngine sharedEngine] logout];
查看更多
登录 后发表回答