Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 删除应用程序的缓存_Ios_Swift_Xcode - Fatal编程技术网

Ios 删除应用程序的缓存

Ios 删除应用程序的缓存,ios,swift,xcode,Ios,Swift,Xcode,我想删除我的应用程序的缓存。 我想使用UIWebView显示网页 我当前的代码: import UIKit class ViewController: UIViewController { @IBOutlet weak var webBrowser: UIWebView! webBrowser:(UIWebView *)webBrowser shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(U

我想删除我的应用程序的缓存。 我想使用UIWebView显示网页

我当前的代码:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var webBrowser: UIWebView!
    webBrowser:(UIWebView *)webBrowser shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    override func viewDidLoad() {
        super.viewDidLoad()
        let url = NSURL(string:"http://127.0.0.1:8000/admin/accounts/")
        let request = NSURLRequest(url:url! as URL)
        self.webBrowser.loadRequest(request as URLRequest)
        // Do any additional setup after loading the view, typically from a nib.
    }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
当我添加此代码时

webBrowser:(UIWebView *)webBrowser shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
到ViewController,因此发生“预期声明”错误。 我的代码有什么问题? 我应该在某种程度上连接我的故事板和代码吗?
如何修复此问题?

要删除缓存,请尝试下面的代码

URLCache.shared.removeAllCachedResponses()
URLCache.shared.diskCapacity = 0
URLCache.shared.memoryCapacity = 0
否则,您还可以更改NSURLRequest的缓存策略

let url = URL(string: "http://127.0.0.1:8000/admin/accounts/")
let request = URLRequest(url: url!,
    cachePolicy:NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData,
    timeoutInterval: 10.0)
self.webBrowser.loadRequest(day_url_request)
这是目标C代码。按如下方式更新代码

class ViewController: UIViewController,UIWebViewDelegate  {

    @IBOutlet weak var webBrowser: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        let url = NSURL(string:"http://127.0.0.1:8000/admin/accounts/")
        let request = NSURLRequest(url:url! as URL)
        self.webBrowser.delegate = self
        self.webBrowser.loadRequest(request as URLRequest)
        // Do any additional setup after loading the view, typically from a nib.
    }

    func webView(_ webView: UIWebView, 
       shouldStartLoadWith request: URLRequest, 
         navigationType: UIWebViewNavigationType) -> Bool
         // do your stuffs
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

您正在使用
Objective-C
code
shouldStartLoadWithRequest:

以下是要加载的swift版本代码
UIWebView

class ViewController: UIViewController,UIWebViewDelegate {

    override func viewDidLoad() {

        var webBrowser: UIWebView!

        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        webBrowser = UIWebView(frame: UIScreen.main.bounds)
        webBrowser.delegate = self
        view.addSubview(webBrowser)
        if let url = URL(string: "http://127.0.0.1:8000/admin/accounts/") {
            let request = URLRequest(url: url)
            webBrowser.loadRequest(request)
        }
    }
}

您添加的行
webBrowser:(UIWebView*)webBrowser应该使用request:(NSURLRequest*)request-navigationType:(UIWebView-navigationType)navigationType
这是一个Objective-C代码。在swift中转换它并再次运行代码。参考这个答案@user8080149thx,你的评论。我有一个关于你代码的问题。func webView(webView:UIWebView,shouldStartLoadWith request:URLRequest,navigationType:UIWebView navigationType)->Bool//do your stuff}您的代码是删除缓存的一部分,对吗?