David David - 3 months ago 14
HTML Question

Best way to refresh a list with events in WebView

I made an iOS app in Swift.

There's also a

UIWebView
in it. This WebView loads a website of my server that contains a list with events. This list/website should reload once a day to keep it up to date.

What is the best way to do it?

Maybe with this meta tag in HTML?

<meta http-equiv="refresh" content="86400">


But, I think this will only count down if the app is open and actually in use. I think this will not work if the app is only open in the background, right?

If so, what's the best an common way to do that?

Answer

I'm using this working solution now: import UIKit

class FirstViewController: UIViewController, UIWebViewDelegate {
    @IBOutlet var homewebview: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        _ = NSTimer.scheduledTimerWithTimeInterval(21600, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)
        self.homewebview.delegate = self
    }
    func update() {
        homewebview.reload()
        NSURLCache.sharedURLCache().removeAllCachedResponses()
        NSURLCache.sharedURLCache().diskCapacity = 0
        NSURLCache.sharedURLCache().memoryCapacity = 0
    }
}