简体   繁体   中英

WatchKit extension: how to read data from host iOS app?

Question background:
The host iOS app generates UIImage dynamically at a frame rate of 10 fps, and I simply want to retrieve the UIImage data from WatchKit extension and show the images on Watch app at the same rate.

My current solution:
I set an app group for both the iOS app and WatchKit extension. The iOS app writes each frame into a png file (about 10k) to the group shared location, and WatchKit extension uses NSTimer to read the file at the same rate, then post the data to Watch app.

Problem:
It works with very bad performance. The Watch app misses frames hence the animation is very badly presented. The root cause might be WatchKit extension's file read operation, or the data wirelessly transfer from extension to watch app.

Does anyone has a similar requirement?
Is there better solution for:

  1. Read data from iOS app to WatchKit extension?
  2. Show dynamic images on watch app?

You're experiencing bad performance because the run cycles are never perfect, and the synchronized calls are not perfectly aligned.

The correct way to solve this is not to generate the images on the fly like you are, but rather before you need them.

You could either generate these images in Xcode and include them in your WatchKit App's bundle (if they're something general you'll be using a lot), you can generate them when the WatchKit app launches (if you know what you'll need and that you'll need them later), or you can generate them a little before you actually need them.

If going for one of the latter two, the best practice is like you're doing now, to store them in a shared app group (not use openParentApplication:reply: ). However, you have to be careful when accessing and writing to the same group at the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM