Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 为什么红蜘蛛不再在真正的苹果手表(WatchOS 6)上工作?_Swift_Websocket_Apple Watch_Starscream_Watchos 6 - Fatal编程技术网

Swift 为什么红蜘蛛不再在真正的苹果手表(WatchOS 6)上工作?

Swift 为什么红蜘蛛不再在真正的苹果手表(WatchOS 6)上工作?,swift,websocket,apple-watch,starscream,watchos-6,Swift,Websocket,Apple Watch,Starscream,Watchos 6,最近我把我的Apple Watch升级到了WatchOS 6.0.1,把我的iPhone升级到了iOS 13.1.2,把Xcode升级到了11.1。MacOS仍然是10.14.6 我创建了一个独立的Apple Watch项目,在该项目中,我使用红蜘蛛测试手表和WebSocket服务器之间的通信: 它在模拟器上运行得很好,但在真正的Apple Watch上,当我尝试连接到服务器时,我发现以下错误: 2019-10-08 18:57:53.064887+0200 BackgroundWebSocke

最近我把我的Apple Watch升级到了WatchOS 6.0.1,把我的iPhone升级到了iOS 13.1.2,把Xcode升级到了11.1。MacOS仍然是10.14.6

我创建了一个独立的Apple Watch项目,在该项目中,我使用红蜘蛛测试手表和WebSocket服务器之间的通信:

它在模拟器上运行得很好,但在真正的Apple Watch上,当我尝试连接到服务器时,我发现以下错误:

2019-10-08 18:57:53.064887+0200 BackgroundWebSocketOnlyWatch WatchKit Extension[251:31011] [] nw_connection_get_connected_socket [C1] Client called nw_connection_get_connected_socket on unconnected nw_connection

2019-10-08 18:57:53.068928+0200 BackgroundWebSocketOnlyWatch WatchKit Extension[251:31011] TCP Conn 0x16d8d5f0 Failed : error 0:50 [50]

websocket is disconnected: Optional("The operation couldn’t be completed. Network is down")
我将向您显示我的应用程序的代码:

InterfaceController.swift

import WatchKit
import Foundation
import Starscream

class InterfaceController: WKInterfaceController, WebSocketDelegate {

let socket = WebSocket(url: URL(string: "ws://echo.websocket.org/")!)

@IBOutlet var label: WKInterfaceLabel!

/**************************************************************************************************/

override func awake(withContext context: Any?) {
    super.awake(withContext: context)

    socket.delegate = self
}

override func willActivate() {
    // This method is called when watch view controller is about to be visible to user
    super.willActivate()
}

override func didDeactivate() {
    // This method is called when watch view controller is no longer visible
    super.didDeactivate()
}

/************************************************************************************************/

@IBAction func connectButtonPressed() {

    socket.connect()
}

@IBAction func sendButtonPressed() {

    socket.write(string: "Hi!")
}

@IBAction func disconnectButtonPressed() {

    socket.disconnect()
}

/******************************************************************************************/

func websocketDidConnect(socket: WebSocketClient) {
    print("websocket is connected")
    label.setText("Connected")
}
func websocketDidDisconnect(socket: WebSocketClient, error: Error?) {
    print("websocket is disconnected: \(error?.localizedDescription)")
    label.setText("Disconnected")
}
func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
    print("got some text: \(text)")
    label.setText("Received: \(text)")
    createVibration()

}
func websocketDidReceiveData(socket: WebSocketClient, data: Data) {
    print("got some data: \(data.count)")
}
/******************************************************************************************/

// Creates vibration
func createVibration() {

    WKInterfaceDevice.current().play(.notification)
    print("Vibration created")
}
}

我试着在iOS 13.1.2上使用红蜘蛛,它在模拟器和真正的iPhone上都能完美运行

这是WatchOS 6的一个bug,还是红蜘蛛需要升级

提前感谢!:)


编辑:2019年11月5日

我已经将我的Apple Watch升级为WatchOS 6.1,将iPhone升级为iOS 13.2,而WebSocket仍然无法在手表上工作

但出现了一些新错误:

2019-11-05 12:33:29.317757+0100 BackgroundWebSocketBothDevices WatchKit Extension[269:37201] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:4 Err:-1 Errno:1 Operation not permitted

2019-11-05 12:33:29.317919+0100 BackgroundWebSocketBothDevices WatchKit Extension[269:37201] [] nw_resolver_create_dns_service_locked [C1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)

2019-11-05 12:33:29.319083+0100 BackgroundWebSocketBothDevices WatchKit Extension[269:37255] [] nw_connection_get_connected_socket [C1] Client called nw_connection_get_connected_socket on unconnected nw_connection

2019-11-05 12:33:29.319150+0100 BackgroundWebSocketBothDevices WatchKit Extension[269:37255] TCP Conn 0x155a7360 Failed : error 0:-65563 [-65563]

websocket is disconnected: The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -72000.)

不幸的是,WatchOS us缺少kCFStream属性来实现此功能