Clear iPhone simulator cookies

柔情痞子 提交于 2019-12-20 15:37:06

问题


I have an app that makes request to a REST service. Authentication is done using cookies. This already works.

What I have problems with is to test the case when the cookie is no longer valid and my code has to reauthenticate. To test this I have to wait until the cookie is invalid, which could take some time. To accelerate this I figured that if I delete the cookie it would have the same effect.

How to delete all cookies of an app on the iPhone simulator?

I already tried the following:

Deleting <app-dir>/Library/Cookies/Cookies.binarycookies doesn't work. It seems that my cookies are never written to this file.

Deleting all cookies in NSHTTPCookieStorage on app startup doesn't work either.


回答1:


The cookies are located at:

/Users/<YourUsername>/Library/Application Support/iPhone Simulator/<iOSversion>/Library/Cookies/Cookies.binarycookies

You may need to quit out of Safari (in the fast app switching area) and then delete them so Safari won't have them in memory.




回答2:


YOU CAN RESET THE SIMULATOR

  • Launch the simulator.
  • Click the FIRST item on the "menu bar". It says "iOS Simulator"
  • A menu will appear. Go down three items to "Reset Contents and Settings"
  • Click "Reset" on the dialog which appears




回答3:


You'll probably find better luck doing this in the SDK code rather than modifying file systems. Try:

    //Delete previous cookies
    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *each in [[[cookieStorage cookiesForURL:YOUR_URL] copy] autorelease]) {
        [cookieStorage deleteCookie:each];
    }



回答4:


I just used fseventer to inspect what happens to the iPhone Simulator filesystem when the "Clear Cookies and Data" button is tapped. These commands replicate that behavior, however, there is a trick:

rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Library/Cookies"
rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Library/Caches/Snapshots"
rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Library/Caches/com.apple.mobilesafari"
rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Library/WebKit"
rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Library/Safari"

The Simulator needs to be restarted. So, before manipulating the filesystem, I run this:

killall "iPhone Simulator"



回答5:


You can go to the home screen, then the settings app. Tap Safari, then scroll down to Clear Cookies. I'm not sure where the cookie file is on the filesystem, somewhere under /Developer/Platforms/iPhoneSimulator.platform I'd expect (see Matthew Frederick's answer).




回答6:


Why not force cookie expiration to a low value for testing?

That is exactly the same then.



来源:https://stackoverflow.com/questions/4427165/clear-iphone-simulator-cookies

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