简体   繁体   English

WKWebView是否支持websocket?

[英]Does the WKWebView support websocket?

I have very short question. 我的问题很简短。 I'm starting to develop an app, which is targeted to Android, but why not try to use it on iOS? 我开始开发针对Android的应用程序,但是为什么不尝试在iOS上使用它呢? Application has WebView only and it will use WebSocket for communication. 应用程序仅具有WebView,它将使用WebSocket进行通信。

My question is, does the UIWebView support WebSocket or is it necessary to use external libraries? 我的问题是,UIWebView是否支持WebSocket还是需要使用外部库? I don't have an Apple device to check and didn't find any information in the internet. 我没有要检查的Apple设备,也没有在互联网上找到任何信息。

Thanks for any hint. 感谢您的任何提示。

EDIT:I've read that UIWebView is deprecated. 编辑:我已经阅读过不推荐使用UIWebView。 What about WKWebView? WKWebView呢?

I have found that WKWebView does support Web Sockets. 我发现WKWebView确实支持Web套接字。 What really surprised me is it also supports keeping the websockets open in the background (assuming you have the appropriate requirements set up in your app). 真正令我惊讶的是,它还支持将Websocket在后台保持打开状态(假设您在应用中设置了适当的要求)。 You can then pass messages to the native side as required using the messageHandlers.postMessage mechanism. 然后,您可以根据需要使用messageHandlers.postMessage机制将消息传递到本机端。

Alternatively if you wanted to take a more native approach you could use SocketRocket which is a library developed by Facebook 另外,如果您想采用更原生的方法,则可以使用由Facebook开发的库SocketRocket

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM