I am trying to build a jogging app that communicates with the Apple Watch app. When I press the "Start" button, the iOS app should signal my Watch app to start keeping track of my workout. (e.g. Showing time elapsed, measure heart rate, and etc) To make that possible, the iOS and WatchOS app should communicate. The problem with my app is that my WatchOS app can only receive a signal from my iOS app when it is on. (e.g. Watch screen is on)
This is a code from my iOS app:
@objc func startAction() {
if WCSession.isSupported() {
print("WC session is supported...")
let session = WCSession.default
session.delegate = self
session.activate()
session.sendMessage(["testWorkout":true], replyHandler: nil) { error in
print("ERROR: (error.localizedDescription)")
}
}
}
And this is code from the other end (From the watch's end):
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
WKInterfaceDevice.current().play(.start)
print("message test workout")
}
I get a play sound and the printout message: "message test workout" when Apple Watch is on, but
when Apple Watch's screen is off, the WatchOS app receives no signal. What code can I write from iOS app's end (Or anything else I can do from WatchOS app's end) to wake up the WatchOS app?
question from:
https://stackoverflow.com/questions/65945620/why-can-my-apple-watch-os-app-receive-message-from-my-ios-app-only-when-it-is-ac 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…