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

こ雲淡風輕ζ 提交于 2019-12-04 08:29:28

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.

In my case for refresh my UI instantaneously on device:

   func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) {
     //receive message from watch
     dispatch_async(dispatch_get_main_queue()) {
        self.textLabel.text = message["optionSent"]! as? String
     }

   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!