didReceiveMessage receives and responds to message but method not called

709 Views Asked by At

Watch app interface controller :

@IBAction func scheduleMeeting(_ sender: WKInterfaceButton) {
        if (WCSession.isSupported()) {
            session.sendMessage([ "scheduleMeeting": ["scheduleMeeting"] ], replyHandler: { (responses) -> Void in
                print("response: \(responses)")
            }) { (err) -> Void in
                print("error: \(err)")
            }
        }
    }

iOS app main view controller:

class ParentViewController: UIViewController, WCSessionDelegate {
    var session: WCSession?

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

        //FYI i have tried this  -DispatchQueue.main.async { - but no difference
        print("test1")
        do {
            //since we are passing true for asynchronous we cannot use the result of the call, the warning below is n/a
            try 
Communicator.addScheduledMeeting(self.scheduledMeeting, asynchronous: true)
        } catch {
            print("Unexpected saving scheduled meeting error: \(error).")
        }

        // Send a reply
        replyHandler(["Message":"Hi from app"])

    }
//omitted rest of class

As we can see from the console output (below), the message is received by the app and response is sent back

response: ["Message": Hi from app]

my problem is that none of the other code there is ran

  • print("test1") never shows on console
  • breakpoints within didReceiveMessage and Communicator.addScheduledMeeting are not hit

Side note I don't know if its related but I feel that it might be and I should mention it.
to run my watch app I select " WatchKit App" and hit play (its in this mode that my console output is from). however during this time, my app is only present on the watch emulator. If I try to open it on the iPhone simulator, it opens shows activity indicator, then goes black then back to home screen. If I select just "" and hit play the app runs fine. I can manually launch the watch app but nothing to the console nor any breakpoints.

0

There are 0 best solutions below