How to logout of twitter using fabric in iOS application

不打扰是莪最后的温柔 提交于 2019-12-23 15:44:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!