问题描述
我有一个很简短的问题.我开始开发一个针对 Android 的应用程序,但为什么不尝试在 iOS 上使用它呢?应用程序只有 WebView,它将使用 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? Application has WebView only and it will use WebSocket for communication.
我的问题是,UIWebView 支持 WebSocket 还是需要使用外部库?我没有要检查的 Apple 设备,也没有在互联网上找到任何信息.
My question is, does the UIWebView support WebSocket or is it necessary to use external libraries? I don't have an Apple device to check and didn't find any information in the internet.
感谢您的任何提示.
我读过 UIWebView 已被弃用.WKWebView 呢?
I've read that UIWebView is deprecated. What about WKWebView?
推荐答案
我发现 WKWebView 确实支持 Web Sockets.真正让我惊讶的是它还支持在后台保持 websockets 打开(假设您在应用程序中设置了适当的要求).然后,您可以根据需要使用 messageHandlers.postMessage
机制将消息传递到本机端.
I have found that WKWebView does support Web Sockets. 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). You can then pass messages to the native side as required using the messageHandlers.postMessage
mechanism.
或者,如果您想采用更原生的方法,您可以使用 SocketRocket,这是一个由 Facebook 开发的库
Alternatively if you wanted to take a more native approach you could use SocketRocket which is a library developed by Facebook
这篇关于WKWebView 是否支持 websocket?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!