简体   繁体   English

WatchKit扩展:如何从主机iOS应用读取数据?

[英]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. 主机iOS应用以10 fps的帧速率动态生成UIImage,我只想从WatchKit扩展中检索UIImage数据,并以相同的速率在Watch应用上显示图像。

My current solution: 我当前的解决方案:
I set an app group for both the iOS app and WatchKit extension. 我为iOS应用程序和WatchKit扩展设置了应用程序组。 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. iOS应用程序将每个帧写入一个png文件(约10k)到组共享位置,并且WatchKit扩展使用NSTimer以相同的速率读取文件,然后将数据发布到Watch应用程序。

Problem: 问题:
It works with very bad performance. 它的性能非常差。 The Watch app misses frames hence the animation is very badly presented. Watch应用错过了帧,因此动画呈现得很差。 The root cause might be WatchKit extension's file read operation, or the data wirelessly transfer from extension to watch app. 根本原因可能是WatchKit扩展程序的文件读取操作,或数据从扩展程序无线传输到watch应用程序。

Does anyone has a similar requirement? 有人有类似的要求吗?
Is there better solution for: 是否有更好的解决方案:

  1. Read data from iOS app to WatchKit extension? 从iOS应用读取数据到WatchKit扩展程序?
  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. 您既可以在Xcode中生成这些图像,也可以将它们包含在WatchKit App的捆绑软件中(如果您经常使用它们,这很常见),则可以在WatchKit应用启动时生成它们(如果您知道需要什么)并且稍后会需要它们),或者您可以在实际需要它们之前生成它们。

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: ). 如果要使用后两者之一,则最佳实践是像您现在所做的那样,将它们存储在共享的应用程序组中(不要使用openParentApplication:reply: However, you have to be careful when accessing and writing to the same group at the same time. 但是,在同时访问和写入同一组时必须小心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从父级ios应用程序调用watchkit扩展中的方法 - How to call the method in watchkit extension from parent ios app 通过WatchKit扩展检测iOS应用是否在前台 - Detect if iOS app is in foreground from WatchKit extension iOS - WatchKit如何将消息/数据从iPhone应用程序发送到WatchKit应用程序? - iOS - WatchKit how to send message/data from iPhone app to WatchKit app? 如何从iOS应用显示Watchkit概览 - How display watchkit glance from iOS app iOS WatchKit - 如何确定您的代码是在手表扩展程序还是应用程序中运行 - iOS WatchKit - how to determine if your code is running in watch extension or the app 如何通过存储“回复”块在iOS应用和WatchKit扩展之间进行通信? - How to communicate between an iOS app and the WatchKit extension by storing the “reply” block? 如何在 iOS 中的扩展和主机应用程序之间共享后删除数据 - How to remove data after share between extension and host app in iOS 如何使用主机应用程序中的数据更新iOS 10 Today小部件扩展? - How to update iOS 10 today widget extension with data from host app? 具有WatchKit扩展名的父级应用程序是否为iOS 8及更高版本? - Does parent app with WatchKit extension be iOS 8 and later? 使用WatchKit和iOS App的核心数据 - Core Data with WatchKit and iOS App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM