"Execution of the command buffer was aborted due to an error during execution" 在 Apple Watch 应用程序上?

"Execution of the command buffer was aborted due to an error during execution" on Apple Watch App?

2020-01-18 18:03:02.316685-0500 Watch Extension[529:813076] Execution of the command buffer was aborted due to an error during execution. Insufficient Permission (to submit GPU work from background) (IOAF code 6)

我在测试 3 个 HealthKit 应用程序时开始反复打印此控制台消息,但我无法弄清楚它与什么有关,而之前的 SO 问题仅与 iPhone 有关。具体来说,我似乎可以在模拟锻炼动作(即慢跑)时触发它。知道什么会导致手表上显示此消息吗?

编辑:我认为问题是 SKScene 我用来在手表应用程序上显示动画。当我注释掉下面的内容时,我不再看到控制台警告:

 @IBOutlet var spriteKitScene1: WKInterfaceSKScene!
    @IBOutlet var spriteKitScene2: WKInterfaceSKScene!

HealthKit 必须使用 Metal,或者您应用中的某些东西正在使用。 Metal 不允许后台处理。

要消除警告,您需要暂停或挂起任何使用 Metal 的进程。

在你的AppDelegate.swift文件中,你可以实现这两个方法:

func applicationWillResignActive(_ application: UIApplication) {
    //Pause or suspend any operations using Metal
}

func applicationDidBecomeActive(_ application: UIApplication) {
    //Resume or start operations using Metal
}

输入 background/foreground 时进行 start/stop 操作的另一种方法是使用通知。如果你喜欢那种模式,我会 post 个例子。

请注意,您看到的是一条警告,表明后台未进行金属处理。如果您的应用按预期运行,您可以忽略警告。