我搜索了这个标题,但没有找到任何适当的信息。我已经找到了将网络请求发送到包含应用程序的网络请求的方法。但是,我想直接回复扩展并在那里显示信息。我已经面临一些使用javascript访问网页的方法,但没有任何关于向后端发出请求的信息。是否有可能提出一些请求并获得JSON响应或在iOS中共享扩展(iPhone,如果有关系)?任何信息或指南将不胜感激!
I've searched around this title, but didn't find any appropriate information. I've found ways to make network request that sends it's result to containing app. However, I wanna get response directly back to extension and show information there. I've faced some ways to use javascript to access webpage, but there was nothing about making request to backend. Is it possible to make some request and get JSON response in action or share extension in iOS (iPhone, if matters)? Any info or guides will be appreciated!
推荐答案您可以直接从扩展程序使用URLSession。 www.raywenderlich/158106/有一个很好的教程urlsession-tutorial-getting-started
You can use URLSession directly from the extension. There is a good tutorial at www.raywenderlich/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无济于事。只需向您的网址发出请求并处理回复。
JavaScript won't help in this case. Just make a request to your url and handle the response.
更多推荐
来自共享或操作扩展ios的网络请求
发布评论