-
Creator 版本:2.2.1
-
目标平台: IOS
websocket在IOS下主动调用close方法关闭不掉连接,服务器端也收不到关闭命令,安卓和web都能正常关闭;
- 重现步骤:在切后台onHide中主动关闭连接,在切会前台onShow中重新连接,发现在onHide中close的连接没有关闭掉,服务器端也收不到关闭命令,并且只有在IOS中才会出现。打印的this.socket.readyState一直是1,表示连接中。
主要代码如下:
`
start() {
this.connect();
let self = this;
wx.onShow(function () {
console.warn("onshow");
self.connect();
}.bind(self));
wx.onHide(() => {
console.warn("onhide");
self.socket.close()
console.warn("当前ws状态:", this.socket.readyState);
})
}
connect() {
this.stop();
this.socket && this.socket.close();
let url = xxx;
this.socket = wx.connectSocket({ url: url });
console.log("this.socket", this.socket);
this.socket.onOpen((e) => { console.log("wssssss open", e) });
this.socket.onMessage((e) => { console.log("wsssss onmessage", e) });
this.socket.onClose((e) => { console.warn("wsssss close", e) });
this.socket.onError((e) => { console.warn("wsssss error", e) });
}`