清除 iPhone 模拟器 cookie

发布于 2024-10-07 15:10:43 字数 474 浏览 9 评论 0原文

我有一个向 REST 服务发出请求的应用程序。身份验证是使用 cookie 完成的。这已经有效了。

我遇到的问题是测试 cookie 不再有效并且我的代码必须重新进行身份验证的情况。为了测试这个,我必须等到 cookie 无效,这可能需要一些时间。为了加速这个过程,我想如果我删除 cookie 也会有同样的效果。

如何删除iPhone模拟器上某个应用程序的所有cookie?

我已经尝试过以下操作:

删除/Library/Cookies/Cookies.binarycookies 不起作用。看来我的 cookie 从未写入此文件。

在应用程序启动时删除 NSHTTPCookieStorage 中的所有 cookie 也不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

寄人书 2024-10-14 15:10:43

您可以重置模拟器

  • 启动模拟器。
  • 单击“菜单栏”上的第一个项目。它显示“iOS Simulator”
  • 将出现一个菜单。向下三项“重置内容和设置”,
  • 在出现的对话框中单击“重置”

iPhone Simulator Reset Cookies

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

iPhone Simulator Reset Cookies

若言繁花未落 2024-10-14 15:10:43

您可能会发现在 SDK 代码中执行此操作比修改文件系统更幸运。
尝试:

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

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];
    }
慕巷 2024-10-14 15:10:43

Cookie 位于:

/Users//Library/Application Support/iPhone Simulator//Library/Cookies/Cookies.binarycookies

您可以需要退出 Safari(在快速应用程序切换区域),然后删除它们,以便 Safari 不会将它们保留在内存中。

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.

硬不硬你别怂 2024-10-14 15:10:43

我刚刚使用 fseventer 来检查发生了什么点击“清除 Cookie 和数据”按钮时的 iPhone 模拟器文件系统。这些命令复制了该行为,但是有一个技巧:

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"

模拟器需要重新启动。因此,在操作文件系统之前,我运行以下命令:

killall "iPhone Simulator"

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"
饭团 2024-10-14 15:10:43

您可以转到主屏幕,然后转到设置应用程序。点击 Safari,然后向下滚动到“清除 Cookie”。我不确定 cookie 文件在文件系统上的位置,我期望的 /Developer/Platforms/iPhoneSimulator.platform 下的某个位置(请参阅 Matthew Frederick 的回答)。

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).

婴鹅 2024-10-14 15:10:43

在较新的 MacOS 版本中重置模拟器:

启动模拟器。

  • 单击“菜单栏”上的“设备”。
  • 将出现一个菜单。向下两项选择“删除所有内容和设置...”,
  • 然后在出现的对话框中单击“重置”

如何重置ios模拟器

Resetting the simulator in newer MacOS versions:

Launch the simulator.

  • Click "Device" on the "menu bar".
  • A menu will appear. Go down two items to "Erase All Contents and Settings..."
  • Click "Reset" on the dialog which appears

how to reset ios simulator

妄司 2024-10-14 15:10:43

为什么不强制 cookie 过期时间为一个较低的值来进行测试?

那是完全一样的。

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

That is exactly the same then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文