简体   繁体   English

CoreMotion主线程检查器警告,仅出现在2018型号iPhone上

[英]Main Thread Checker warning with CoreMotion, only appearing on 2018 model iPhones

The following is an extremely simplified version of the issue: 以下是该问题的极简化版本:

import UIKit
import CoreMotion

class ViewController: UIViewController {
    private let manager = CMMotionManager()
    private let interval = 0.01

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        startUpdates()
    }

    private func startUpdates() {
        let queue = OperationQueue()
        queue.name = "com.demo.motion"
        queue.qualityOfService = .userInteractive
        queue.maxConcurrentOperationCount = 1
        manager.accelerometerUpdateInterval = interval
        manager.startAccelerometerUpdates(to: queue) { _, _ in }
    }
}

When I run this on an iPhone XR, I will receive the following: 当我在iPhone XR上运行时,我会收到以下信息:

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState] PID: 1237, TID: 147763, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 主线程检查器:在后台线程上调用的UI API: - [UIApplication applicationState] PID:1237,TID:147763,线程名称:com.apple.CoreMotion.MotionThread,队列名称:com.apple.root.default-qos.overcommit ,QoS:0

  • My device is running 12.3 , which is currently the latest iOS release 我的设备运行12.3 ,这是目前最新的iOS版本
  • Running this on various iPads (pre 2018), iPhone 8, iPhone 6S, and other older models, the issue does not appear. 在各种iPad(2018年前),iPhone 8,iPhone 6S和其他旧型号上运行此问题,不会出现此问题。
  • Changing the qualityOfService has no impact on this (my preference is to use utility ) 更改qualityOfService对此没有影响(我的偏好是使用utility
  • Out of curiosity, I wrapped the entire startUpdates() function around a main dispatch with no success 出于好奇,我将整个startUpdates()函数包装在主调度中,但没有成功

Based on the queue name and when this is occurring, my assumption is that this is something internal that is just getting exposed by the faster processor in the XR, versus the older devices. 基于队列名称,当发生这种情况时,我的假设是,这是内部的东西,只是通过XR中较快的处理器而不是旧设备暴露出来。

This is a known issue that has been reported to Apple with a radar linked here . 这是一个已知的问题,已经向苹果公司报告了雷达

Hopefully, it will be addressed soon but I did not see any entries for it on SO and wanted to have something available for others coming across it. 希望它很快就会得到解决,但我没有在SO上看到它的任何条目,并希望为其他人提供一些可用的东西。

If you can, please file a dupe. 如果可以的话,请提出申请。

Fortunately, I have not seen any adverse impacts of this yet . 幸运的是,我还没有见过这样的任何不利影响

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

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