来自共享或操作扩展ios的网络请求

编程入门 行业动态 更新时间:2024-10-16 00:20:13
本文介绍了来自共享或操作扩展ios的网络请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我搜索了这个标题,但没有找到任何适当的信息。我已经找到了将网络请求发送到包含应用程序的网络请求的方法。但是,我想直接回复扩展并在那里显示信息。我已经面临一些使用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的网络请求

本文发布于:2023-11-30 03:34:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648583.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   网络   ios

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!