iphone - NSHTTPCookieStorage 和 Cookie 过期日期

标签 iphone objective-c nshttpcookie

在我们的 iPhone 应用程序中,我们在服务器通信期间使用两个 cookie。一种是短 session cookie (JSESSION),另一种是长 session cookie (REMEMBER ME)。如果服务器有响应,它会发送一个短 session cookie,我可以在 NSHTTPCookieStorage 中找到它。

我的问题是此存储如何处理 cookie 的到期日期?因此,如果 cookie 过期,它是否会自动删除该 cookie,如果我在过期后尝试通过其名称从存储中获取该 cookie,我会得到什么吗?还是我必须手动检查过期时间?

最佳答案

My question is how this storage handles the cookie's expiration date?

NSHTTPCookieStorage 将过期日期作为其属性之一存储 NSHTTPCookie 对象。

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCookie_Class/Reference/Reference.html#//apple_ref/occ/cl/NSHTTPCookie

So if the cookie expires, does it delete that cookie automatically, and if I try to get this cookie by it's name from the storage after expiration, do I get anything? Or do I have to check the expiration manually?

您应该手动检查过期并自行删除 cookie

正如在 http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSHTTPCookie_Class/Reference/Reference.html#//apple_ref/occ/cl/NSHTTPCookie 中提到的那样

The receiver’s expiration date, or nil if there is no specific expiration date such as in the case of “session-only” cookies. The expiration date is the date when the cookie should be deleted.

关于iphone - NSHTTPCookieStorage 和 Cookie 过期日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7203641/

相关文章:

iphone - 如何计算距离用户最近的位置?

iphone - 我的 reloaddata 调用没有调用 UItableviewcontroller 中的委托(delegate)方法?

ios - UITableView 的 NSFetchedResultsController 在插入更改时滚动到顶部

iphone - iOS 无法隐藏工具栏 UIbarButtonItem

iphone - 清除 iPhone 模拟器 cookie

ios - WKHTTPCookieStorage 的 setCookie 在关闭和打开 Web View 后不返回

ios - WebView iOS 不保存 session 或 cookie

iphone - 方向改变

iphone - 以编程方式设置 iphone 模拟器位置

ios - 为什么 Action 在加载完成后执行多次,为什么它对所有事件进行排队?