Jessy1999
Jessy1999

Reputation: 1

(WatchConnectivity) WCSession missing delegate

I am trying to implement messaging between Watch and iPhone where the watch is the one sending data to phone. It has to happen in background therefore I'm using applicationContxt. However, I keep getting these errors whenever I try to run the code: Sometimes it works once and the phone receives data then the errors start.

[WC] -[WCSession handleApplicationContextWithPairingID:]_block_invoke delegate (null) does not implement session:didReceiveApplicationContext:

[WC] WCSession is missing its delegate
import WatchConnectivity

class PhoneWorkingSet: NSObject,  WCSessionDelegate {

    override init() {
        super.init()
       }
    
    func startSession() {
       if WCSession.isSupported() {
        let session = WCSession.default
        session.delegate = self
        session.activate()
        }
    }
    

    func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
    
        print("Received: \(applicationContext)")
    }
    
    
    
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
        if(!session.isReachable) {
            print("Watch not reachable")
        } else {
            print("Watch Reachable")
        }
    }
    
    func sessionDidBecomeInactive(_ session: WCSession) {
        print("has contentPending: \(session.hasContentPending)")
    }
    
    func sessionDidDeactivate(_ session: WCSession) {
        
    }
  

}

Upvotes: 0

Views: 616

Answers (0)

Related Questions