如果有一个主题,人们可以使用新语言Swift轻松了解如何在Webview中管理cookie?如果您在互联网上办理登机手续,则在需要实施时无法找到任何有趣的内容.甚至苹果的文档都很差.
有人知道如何在Swift中处理这些过程吗?这是我在Obj-C中找到的:
看到COOKIES存储
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
NSLog(@"%@", cookie);
}
Run Code Online (Sandbox Code Playgroud)
删除存储的COOKIES
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
Run Code Online (Sandbox Code Playgroud)
如果我们能给出一次这样的答案,对每个人来说都会很好!干杯!
我的应用程序中有一个UIWebView.每次都需要完全重新加载此UIWebView(即清除所有图像/ HTML/cookie缓存等)viewDidLoad.
那么在Swift中我可以做任何代码吗?
这是我的代码:
let myUrl = NSURL(string: "http://www.example.com")
let myRequest = NSURLRequest(URL: myUrl!)
myWebView.loadRequest(myRequest)
Run Code Online (Sandbox Code Playgroud)
谢谢!