8
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

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
S. Chand
  • 209
  • 4
  • 16

2 Answers2

12

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

Reno Jones
  • 1,979
  • 1
  • 18
  • 30
  • 1
    It worked !!! with below code inside for in if ([[each valueForKey:@"domain"] isEqualToString:@".twitter.com"]) { [cookieStorage deleteCookie:each]; } Thanks buddy.. – S. Chand Jul 06 '13 at 06:44
4

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];
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132