【发布时间】:2023-04-06 22:21:01
【问题描述】:
我现在的代码删除了*.localstorage 和备份的localStorage 文件,但是无论文件是否被删除,下次打开web 视图时localStorage 仍然存在。
编辑:我必须删除所有域的 localStorage! IE。注入 JS 不起作用。
class func clearWebViewStorage() {
let searchPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomainMask.UserDomainMask, true).last as! String
let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(searchPath, error:nil) as! [String]
for file in files {
if file.pathExtension == "localstorage" {
NSLog("Removing localstorage file: %@", searchPath.stringByAppendingPathComponent(file))
NSFileManager.defaultManager().removeItemAtPath(searchPath.stringByAppendingPathComponent(file), error: nil)
}
}
var path = searchPath.stringByAppendingPathComponent("Backups").stringByAppendingPathComponent("localstorage.appdata.db")
NSLog("Removing localstorage backup %@", path)
NSFileManager.defaultManager().removeItemAtPath(path, error: nil)
}
【问题讨论】:
标签: ios swift cocoa-touch uiwebview local-storage