How to manage cookies with UIWebView in Swift

后端 未结 8 834
心在旅途
心在旅途 2020-12-02 11:53

What about have a topic where people can easily see how to manage cookies in a webview using the new language Swift? If you check in internet you won\'t find anything intere

相关标签:
8条回答
  • 2020-12-02 12:11

    Logout for api VKontakte, swift 3+

    let dataStore = WKWebsiteDataStore.default()
    dataStore.fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { (records) in
        for record in records {
            if record.displayName.contains("facebook") {
                dataStore.removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), for: [record], completionHandler: {
                    print("Deleted: " + record.displayName);
                })
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-02 12:20

    If you are working on swift 4 then this code will disable cookies and also remove the URL cache.

    let cookieJar : HTTPCookieStorage = HTTPCookieStorage.shared
    for cookie in cookieJar.cookies! as [HTTPCookie]{
        NSLog("cookie.domain = %@", cookie.domain)
         cookieJar.deleteCookie(cookie)
    }
    
    URLCache.shared.removeAllCachedResponses() 
    URLCache.shared.diskCapacity = 0 
    URLCache.shared.memoryCapacity = 0
    
    0 讨论(0)
提交回复
热议问题