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
qualityOfService
has no impact on this (my preference is to use utility
)startUpdates()
function around a main dispatch with no successBased 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With