Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why sending message from WatchKit extension to iOS and getting back a reply is so slow?

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:

  1. Why is it so slow?
  2. Is it supposed to be so slow?
  3. Is there a way to make it faster?

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

like image 855
Evgenii Avatar asked Sep 20 '15 10:09

Evgenii


People also ask

What is a WatchKit extension?

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.

How do you reply to a message on Iwatch?

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.

How do you change quick reply on Apple Watch?

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.


1 Answers

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.

like image 90
jeeeyul Avatar answered Oct 03 '22 15:10

jeeeyul