我想通过Swift函数在我的服务器上点击URL来自动执行在服务器上执行的操作。我不需要回复。我只需要在服务器上找到正确的URL。我需要swift代码(函数)来执行它。我有这个工作在旧swift但它不再工作在swift 3.我需要通过应用程序中的UISwitch一个动作点击两个URL。非常感谢您的帮助,请提供完整的功能代码,以便我在新的时候执行任务。非常感谢您的帮助。谢谢。
答案 0 :(得分:0)
点击你的网址和线程,
DispatchQueue.global(qos: .background).async {
// do things which can run in background
// calculations-delay-waiting for a response etc.
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
// implement UI related part which has to run in main thread.
}
})
}
答案 1 :(得分:0)
好的,我解决了我的问题...
func functionName () {
// Trigger Automation URL
var request = URLRequest(url: URL(string: "http://www.handofgodapp.com/automate?key= SUQ3VExRg==&activate=1")!)
request.httpMethod = "POST"
let session = URLSession.shared
session.dataTask(with: request) {data, response, err in
print("Entered the completionHandler")
}.resume()
}