I am using sendMessage
method to send a message from WatchKit extension to an iOS app. It takes about 230 ms on average to receive a reply. The time does not depend on whether the iOS app is on screen or running in the background. 230ms is roughly the time it takes for light to travel the Earth circumference and back. But the phone is sitting 30 cm from my watch when I am testing this.
Questions:
An observation: according my previous experiments in watchOS 1 communication was a bit faster, a roundtrip used to take about 50 ms.
Send a message from WatchKit extension
let session = WCSession.defaultSession()
session.sendMessage(["message from watch":"🌷"], replyHandler: { reply in
// Getting reply from iOS app here
}, errorHandler: nil)
Receive the message from iOS app
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) {
replyHandler(["reply from iOS":"🐱"])
}
Demo app: https://github.com/evgenyneu/WatchKitParentAppBenchmark
iOS: 9.0, watchOS: 2.0
A WatchKit Extension process that executes the watch app's application logic. This is bundled with your Watch app and runs on the Apple Watch. A Watch app that displays user interface elements and handles navigation.
Reply to a messageTurn the Digital Crown to scroll to the bottom of the message, then choose how to reply. To quickly respond with a Tapback, touch and hold a specific message in a conversation, then choose a Tapback—like thumbs-up or a heart.
You can customize these quick replies from the Watch app > My Watch > Mail > Default Replies. From here, the steps are the same as above. That is, tap Add reply to create your custom quick reply, tap a default reply to change it, and tap Edit to switch the order or delete them.
AFAIK, when you send a message to other device, the message will be archived to file on local directory that called as WatchDirectory
.
This directory will be synchronized to other device like as other iCloud Drive App or Drop Box through bluetooth. Because this approach doesn't need App running for iOS and watchOS App while the transfer will be finished.
When the new files were arrived on directory, iOS(or watchOS) will invoke WCSession related API to process content. If needed, iOS(or watchOS) will awake the destination App in background before dispatch message.
With watchOS1, the watch extension runs on iOS, only remote UI runs on AppleWatch. So it requires much more simple process to communicate, just communication between processes.
sendMessage
is much more expensive method than other communication API those are provided by WCSession
. iOS can't use it till the watch App runs foreground, And using sendMessage
from watchOS should have to wake up iPhone and launch iOS App in background. After the dispatched messages were handled, iOS may kill the destination app that running on background to get memory back.
So, IMO there is no reason that it should be fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With