2017-06-02 73 views
0

我想通过Swift函数在我的服务器上点击URL以自动执行在服务器上执行的操作。我不需要回应。我只需要在服务器上找到正确的URL。我需要swift代码(函数)来执行此操作。我有这个旧swift工作,但它不能在swift 3中工作。我需要通过应用程序中的UISwitch通过一个动作点击两个URL。我非常感谢您的帮助,请提供完整的功能代码以执行我新的任务。您的帮助将不胜感激。谢谢。在服务器上点击URL以自动执行由服务器执行的操作

回答

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. 


       } 

      }) 
     } 
0

OK我解决我的问题......

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() 
}