A new instance of CMMotionManager results in a Thread Checker warning

Originator:andrea.mazzini
Number:rdar://45003816 Date Originated:04/10/2018
Status:Open Resolved:
Product:iOS Product Version:12
Classification:Bug Reproducible:Yes
 
Area:
Core Motion

Summary:
Creating a new instance of CMMotionManager always results in a Thread Checker exception

Steps to Reproduce:
Instantiate a new CMMotionManager in the main thread:
      let motion = CMMotionManager()

Expected Results:
No exception is raised

Actual Results:
The thread checker kicks in:
```
Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 9123, TID: 1958556, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x00000002079d7894 <redacted> + 56
5   CoreMotion                          0x000000020e2387a4 CoreMotion + 305060
6   CoreMotion                          0x000000020e238cd8 CoreMotion + 306392
7   CoreMotion                          0x000000020e238be8 CoreMotion + 306152
8   CoreMotion                          0x000000020e26a3cc CoreMotion + 508876
9   CoreMotion                          0x000000020e26a42c CoreMotion + 508972
10  CoreFoundation                      0x0000000208770888 <redacted> + 28
11  CoreFoundation                      0x000000020877016c <redacted> + 276
12  CoreFoundation                      0x000000020876af54 <redacted> + 1016
13  CoreFoundation                      0x000000020876a844 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x000000020876b5a8 CFRunLoopRun + 84
15  CoreMotion                          0x000000020e269d64 CoreMotion + 507236
16  libsystem_pthread.dylib             0x00000002083e5a04 <redacted> + 132
17  libsystem_pthread.dylib             0x00000002083e5960 _pthread_start + 52
18  libsystem_pthread.dylib             0x00000002083eddf4 thread_start + 4
2018-10-04 12:09:35.737994+0200 test[9123:1958556] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 9123, TID: 1958556, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
```

Version/Build:
iOS 12
Xcode Version 10.0 (10A255)

Comments

Same issue on iPhone Xr. Seems to be a hardware specific issue to the newer iPhones as my iPhone SE and iPad Mini do not throw this warning. In the latest iOS 12.2 now this is blocking the main thread and causing crashes.

I ran on iPhone XS Max 12.1 shown the same log, but I checked the code and make sure the UI updating on the Main Thread. I ran on iPhone X 12.1.1 and simulator 12.1 not show that log.

Calling [UIView addMotionEffect:] also appears to raise this error, even when [NSThread isMainThread] returns true

Actual problematic line: [self.contentView addMotionEffect:group];

I have found that the same error still occurs in the 12.1 beta.

Minimal source code example

I ran in to the same problem and put together a minimal app to show the problem: https://github.com/doctorcolinsmith/motiontestcrash

I found my sample app will throw the same errors as above on an iPhone Xs running iOS 12.0.1, but not on my iPad. So it appears to be a hardware-specific issue.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!