繁体   English   中英

更新UIWebView Cookie的到期日期

[英]Update expiry date of UIWebView Cookie

我在我的应用程序中显示一个Web登录页面。 我不希望用户一旦登录便再次登录。但是我想登录Cookie在8小时后就过期了。 我可以更新此cookie的到期时间吗? 下面是我得到饼干的代码-

if let cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies {
            for cookie in cookies {
                NSLog("Cookiee name  \(cookie.name)  \n" )
                NSLog("Cookiee value  \(cookie.value) \n")
                NSLog("Cookiee domain  \(cookie.domain) \n")
                NSLog("Cookiee expiresDate \(cookie.expiresDate) \n")
                NSLog("Cookiee path  \(cookie.path) \n")
                NSLog("Cookiee comment \(cookie.comment) \n")
                NSLog("Cookiee commentURL \(cookie.commentURL) \n\n\n")
            }
        }

由此返回的auth cookie的到期日期是2016-09-25 15:09:51 +0000。 如何将其更新为无限?

如果您无法在网站的源代码中设置cookie过期,则可以手动进行。 若要检索和设置具有更新的到期间隔的cookie,您可以按照这种方法。 Swift 3.0提供了更短的代码:

let storage = HTTPCookieStorage.shared
        for cookie in storage.cookies! {

            // catch a cookie info

            storage.deleteCookie(cookie)

            // set a new cookie with update expiration here using catched info
    }

更多文档: https//developer.apple.com/reference/foundation/httpcookiestorage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM