WCSession has not been activated

前端 未结 2 1066
自闭症患者
自闭症患者 2021-02-07 08:57

I get the WCSession has not been activated error when I try to sent something. And I don\'t know what I\'m doing wrong. I have tested serval pre-made solutions what \"must\" wor

2条回答
  •  礼貌的吻别
    2021-02-07 09:21

    I figured out the problem I had, and I think yours is similar. I was trying to send a message immediately after calling activate(), which worked in the past, but since the introduction of the session(activationDidCompleteWith:) function I needed to send my messages from there.

    So I think your solution is one of these:

    1. Make your InterfaceController be the WCSessionDelegate, move all WCSession activation calls there, and send the message from session(activationDidCompleteWith:)
    2. Send the message from session(activationDidCompleteWith:) in the ExtensionDelegate (in my app I handle all communication in the ExtensionDelegate)
    3. Post a notification from session(activationDidCompleteWith:) in the ExtensionDelegate and add an observer to handle it in InterfaceController

    Aside from this, I think you may also have a problem because the declaration of session(didReceiveMessage:) is wrong in your AppDelegate (or at least I had a problem when I tried your code.)

    The new declaration is:

    func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void)
    

提交回复
热议问题