Network request from share or action extension ios

匆匆过客 提交于 2019-12-03 09:42:28

You can use URLSession directly from the extension. There is a good tutorial at https://www.raywenderlich.com/158106/urlsession-tutorial-getting-started

let url = URL(...)
let dataTask = defaultSession.dataTask(with: url) { data, response, error in
  if let error = error {

    // Handle error (error.localizedDescription)
    // ...

  } else if let data = data,
    let response = response as? HTTPURLResponse,
    response.statusCode == 200 {

    // Handle resonse data
    // ...

    DispatchQueue.main.async {
      // Close extension
      // ...
    }
  }
}

JavaScript won't help in this case. Just make a request to your url and handle the response.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!