Why doesn't print() work when sending a message via Apple Watch To iPhone?

217 Views Asked by At

I am learning how to create a companion Watch App for an iPhone app. (Everything is being done on the simulator)

I am sending a message when I tap a button on the Watch app.

session.sendMessage(["Message": "It Worked" ], replyHandler: nil) { (error) in
        print(error)
    }

Then I receive the message in ViewController.swift:

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
    print(message["Message"])
    print("!!!!")
    theLabel.text = message["Message"] as! String

}

Neither print function fire. However I know I am getting the message because my label is being updated. Break points also don't work in this function. If I put another function call in the didRecieveMessage function it will fire.

Is this a bug? It made me think my message wasn't being sent for the longest time because I was just trying to see if the function was firing via print() and breakpoints.

If not a bug, why doesn't print() work?

1

There are 1 best solutions below

0
On

The reason neither is printing is because the debug console is hooked up to the WatchKit app, which you've only programmed to print in the case of an error.

And the reason the "!!!!" and message["Message"] are not printing is because the debug console is not hooked up to the iOS app.

If you hooked the console to the iOS app you would see the print work.