问题
Shared Instance Logout does not work. I know this is a big problem for developers. Does anyone have a solution? Thanks
回答1:
I ran into this issue about 3 months ago and have just now found a solution to this. Apparently clearing cookies does in fact get rid of Twitter's stored information for previously logged in users. The code below is working for me:
!WARNING! Make sure when you first log in that you Disallow Twitter from accessing your accounts on the device. This causes Twitter to force login the user each time instead of looking straight at your Twitter account saved to your device. Hope this helps!
- (IBAction)twitterLogout:(id)sender {
[[Twitter sharedInstance] logOut];
[self.view insertSubview:_logoutTwitter atIndex:16];
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];
}
}
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
来源:https://stackoverflow.com/questions/31925441/how-to-logout-of-twitter-using-fabric-in-ios-application