Swift 3和JSON –通过在后台运行URL更新数据库 [英] Swift 3 and JSON – Updating the database by running a URL in the background
问题描述
我可以访问某个链接(假设它是 www.google. com ),这样当我在浏览器中打开它时,它将更新数据库中JSON代码的特定部分.根据构成链接一部分的数字,它会调整数据中的某个值.
There is a certain link I have access to (let's pretend it's www.google.com), such that when I open it up in my browser, it updates a certain section of the JSON code in my database. Based on the numbers that make up a portion of the link, it adjusts a certain value in the data.
我需要能够在应用程序中打开"此链接,而无需实际打开UIWebview并直观地访问该网站.我只需要数据库内部的JSON数据自行更新(用户不知道它甚至发生过).
I need to be able to "open" this link within the app, without actually opening up a UIWebview and visually visiting the site. I just need this JSON data inside the database to update on its own (with the user unaware that it even happened).
我在这里遇到的问题是我根本不知道该怎么做. 如何在不打开Safari浏览器的情况下访问此链接?
The problem I'm having here is that I simply don't know how this is done. How do I cause this link to be visited without opening up a Safari browser?
推荐答案
您也可以使用UIWebView而不显示它,就像这样(快速3):
You could also use the UIWebView without ever showing it, like this (Swift 3):
func webView() {
let theWebView: UIWebView
theWebView = UIWebView(frame: UIScreen.main.bounds)
theWebView.delegate = self
if let theURL = URL(string: "your URL") {
let request = URLRequest(url: theURL)
theWebView.loadRequest(request)
}
}
只是不要将其添加到视图中.
Just don't add it to the view.
这篇关于Swift 3和JSON –通过在后台运行URL更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!