【问题标题】:Best way to refresh a list with events in WebView用 WebView 中的事件刷新列表的最佳方法
【发布时间】:2016-08-21 14:58:08
【问题描述】:
我用 Swift 制作了一个 iOS 应用。
其中还有一个UIWebView。此 WebView 加载我的服务器的网站,其中包含事件列表。此列表/网站应每天重新加载一次以保持最新状态。
最好的方法是什么?
也许在 HTML 中有这个元标记?
<meta http-equiv="refresh" content="86400">
但是,我认为这只会在应用程序打开并实际使用时才会倒计时。我认为如果应用程序仅在后台打开,这将不起作用,对吧?
如果是这样,最好的常用方法是什么?
【问题讨论】:
标签:
html
ios
xcode
webview
uiwebview
【解决方案1】:
我现在正在使用这个可行的解决方案:
导入 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
}
}