CodeBender
CodeBender

Reputation: 36670

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:

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

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.

Upvotes: 19

Views: 4349

Answers (1)

CodeBender
CodeBender

Reputation: 36670

New answer when using iOS 13

I have tested this just now with the newly released iOS 13 version (17A577) on a 2018 device and it no longer produces the threading error.

Previous answer when using iOS 12

This is a known issue that has been reported to Apple with a radar linked here.

Upvotes: 16

Related Questions