NSHTTPCookies refuse to be deleted

后端 未结 3 1290
长发绾君心
长发绾君心 2020-12-16 04:48

I need a log out button for my app, I have the below code:

        while ([[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] count] != 0) {
                    


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 05:28

    The problem seems to be that the cookies are cached and not saved out to a file immediately.

    If you add a call to [storage _saveCookies] then it works - they are gone for good, even if you terminate the app straight afterwards. Of course, that method is private API, so it won't help you on the App Store. It would be good to find some way to trigger it!

    I also found that the following CoreFoundation API works well - but unfortunately it is not exposed by Apple either:

    extern CFTypeRef _CFHTTPCookieStorageGetDefault();
    extern void CFHTTPCookieStorageDeleteAllCookies( CFTypeRef storage );
    extern void CFHTTPCookieStorageSyncStorageNow( CFTypeRef storage );
    

    ...

    CFTypeRef storage = _CFHTTPCookieStorageGetDefault();
    CFHTTPCookieStorageDeleteAllCookies( storage );
    CFHTTPCookieStorageSyncStorageNow( storage );
    

提交回复
热议问题