Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get completely logout from FHSTwitterEngine in Twitter Rest API v1.1?

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

like image 501
S. Chand Avatar asked Jul 06 '13 05:07

S. Chand


2 Answers

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

like image 58
Reno Jones Avatar answered Oct 03 '22 11:10

Reno Jones


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];
like image 36
Paresh Navadiya Avatar answered Oct 03 '22 10:10

Paresh Navadiya