为什么Starscream无法在真正的Apple Watch(WatchOS 6)上正常工作? [英] Why is Starscream not working anymore on real Apple Watch (WatchOS 6)?
问题描述
最近,我将Apple Watch升级到WatchOS 6.0.1,将iPhone升级到iOS 13.1.2,将Xcode升级到11.1. MacOS仍为10.14.6.
Recently I upgraded my Apple Watch to WatchOS 6.0.1, my iPhone to iOS 13.1.2, Xcode to 11.1. MacOS still 10.14.6.
我创建了一个独立的Apple Watch项目,在其中使用Starscream测试Watch和WebSocket服务器之间的通信: https://github.com/daltoniam/Starscream
I've created an Independent Apple Watch project where I test the communication between the Watch and a WebSocket server using Starscream: https://github.com/daltoniam/Starscream
它在模拟器上完美运行,但是在真实的Apple Watch 上,当我尝试连接到服务器时,我忘记了这些错误:>
It works perfectly on the Simulator but on real Apple Watch when I try to connect to the server I got these errors:
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")
我将向您显示我的应用代码:
I'll show you the code of my app:
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 上使用 Starscream ,并且它在模拟器和真实iPhone上均可完美运行.
I tried using Starscream with iOS 13.1.2 and it works perfectly both on Simulator and real iPhone.
这是WatchOS 6的 bug ,还是Starscream需要升级?
Is this a bug of WatchOS 6 or is Starscream that needs an upgrade?
提前谢谢! :)
编辑:2019年11月5日
5th November 2019
我已将Apple Watch更新为WatchOS 6.1,并将iPhone更新为iOS 13.2,并且WebSocket仍无法在手表上运行...
I've updated my Apple Watch to WatchOS 6.1 and iPhone to iOS 13.2 and WebSocket still doesn't work on the watch...
尽管有一些新的错误:
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不幸的是,我们缺少kCFStream属性来实现此目的.
WatchOS us unfortunately is missing the kCFStream properties to make this work.
这篇关于为什么Starscream无法在真正的Apple Watch(WatchOS 6)上正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!