我写了如下的用户信息传输代码。(我想从iPhone发送消息以观看。)
//iPhone project
if (WCSession.isSupported()) {
session = WCSession.default
session?.delegate = self
session?.activate()}
session!.transferUserInfo(["titles": List_watch,"Colors_watch": c_w])
//Watch project
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
//do something}
它可以工作,但是当我使用下面的交互式消息时,它不起作用。
//iPhone project
if (WCSession.isSupported()) {
session = WCSession.default
session?.delegate = self
session?.activate()}
session!.sendMessage(["titles": List_watch,"Colors_watch": c_w], replyHandler: { replyDict in }, errorHandler: { error in
print("\(error)")
})
//Watch project
func session(_ session: WCSession, didReceiveMessage message: [String: Any], replyHandler: @escaping ([String: Any]) -> Void) {
//do something}
然后errorHandler的错误提示,
Error Domain = WCErrorDomain代码= 7004“ WatchConnectivity会话尚未激活。” UserInfo = {NSLocalizedRecoverySuggestion =激活WatchConnectivity会话。NSLocalizedDescription = WatchConnectivity会话尚未激活。NSLocalizedFailureReason =尚未调用Function ActivateSession。}
这表示WatchConnectivity会话尚未激活,但是,当我只使用User Info Transfer时,它可以正常工作。所以我认为会议已经启动。这是什么问题有人知道吗?