简体   繁体   English

带Cordova的Websocket在iPad上不起作用

[英]Websockets with cordova doesn't work on ipad

I'm trying to implement WebSockets in JS with Cordova. 我正在尝试使用Cordova在JS中实现WebSockets。 I don't use any plugins, I do this with the native WebSockets of JS. 我不使用任何插件,而是使用JS的本地WebSockets进行的。 Basically, my apps connect to the back end, send a message and then wait for the response. 基本上,我的应用程序连接到后端,发送一条消息,然后等待响应。 This works fine on Chrome / Firefox but when I install it on my iPad the front-end WebSockets never connects to the back-end. 这在Chrome / Firefox上可以正常工作,但是当我在iPad上安装它时,前端WebSocket永远不会连接到后端。

So i tried to add some content policy in my meta tag: 所以我试图在我的meta标签中添加一些内容策略:

<meta http-equiv="Content-Security-Policy" content="default-src * gap: file: ws: wss: ; style-src 'self' 'unsafe-inline'; img-src 'self' data: ; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src 'self' ws: ;">

the websocket is created and used like this: websocket的创建和使用方式如下:

ws = new WebSocket('ws://backEndIP:port/')
ws.send('/skeleton/last')
  ws.onmessage = function (event) {
    resolve(event.data);
  }

I don't know what i can be missing. 我不知道我会缺少什么。

EDIT 编辑

I added <access origin='*' allows-arbitrary-loads-for-media='true' allows-arbitrary-loads-in-web-content='true' allows-local-networking='true' /> in config.xml but it still doesn't work. 我在配置中添加了<access origin='*' allows-arbitrary-loads-for-media='true' allows-arbitrary-loads-in-web-content='true' allows-local-networking='true' /> .xml,但仍然无法正常工作。

I think you have to add backEndIP to your cordova whitelist in config.xml. 我认为您必须在config.xml中将backEndIP添加到您的cordova白名单中。

See documentation here : https://cordova.apache.org/docs/en/latest/guide/appdev/whitelist/ 在此处查看文档: https : //cordova.apache.org/docs/en/latest/guide/appdev/whitelist/

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

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