CMotionManager在实例化时崩溃

问题描述 投票:8回答:2

我在为Core Motion实例化我的CMMotionManager对象时遇到了崩溃。这是在运行iOS 12.0.1的iPhone X上。

我可以通过单视图应用程序使用以下视图控制器可靠地重现这一点。

import UIKit
import CoreMotion

class ViewController: UIViewController {
    var motion: CMMotionManager?
    override func viewDidLoad() {
        super.viewDidLoad()

        // This causes a crash on iPhone Xs, iOS 12.0.1
        self.motion = CMMotionManager()
    }
}

完整的示例项目在https://github.com/doctorcolinsmith/motiontestcrash/tree/master

运行上面的代码时,我在调试器中输出以下输出的线程上出现故障。

=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 3634, TID: 630341, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x000000019b0d3894 <redacted> + 56
5   CoreMotion                          0x00000001a19337a4 CoreMotion + 305060
6   CoreMotion                          0x00000001a1933cd8 CoreMotion + 306392
7   CoreMotion                          0x00000001a1933be8 CoreMotion + 306152
8   CoreMotion                          0x00000001a19653cc CoreMotion + 508876
9   CoreMotion                          0x00000001a196542c CoreMotion + 508972
10  CoreFoundation                      0x000000019be6c888 <redacted> + 28
11  CoreFoundation                      0x000000019be6c16c <redacted> + 276
12  CoreFoundation                      0x000000019be67470 <redacted> + 2324
13  CoreFoundation                      0x000000019be66844 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x000000019be675a8 CFRunLoopRun + 84
15  CoreMotion                          0x00000001a1964d64 CoreMotion + 507236
16  libsystem_pthread.dylib             0x000000019bae1a04 <redacted> + 132
17  libsystem_pthread.dylib             0x000000019bae1960 _pthread_start + 52
18  libsystem_pthread.dylib             0x000000019bae9df4 thread_start + 4
2018-10-24 16:19:31.423680-0700 motiontest[3634:630341] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 3634, TID: 630341, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x000000019b0d3894 <redacted> + 56
5   CoreMotion                          0x00000001a19337a4 CoreMotion + 305060
6   CoreMotion                          0x00000001a1933cd8 CoreMotion + 306392
7   CoreMotion                          0x00000001a1933be8 CoreMotion + 306152
8   CoreMotion                          0x00000001a19653cc CoreMotion + 508876
9   CoreMotion                          0x00000001a196542c CoreMotion + 508972
10  CoreFoundation                      0x000000019be6c888 <redacted> + 28
11  CoreFoundation                      0x000000019be6c16c <redacted> + 276
12  CoreFoundation                      0x000000019be67470 <redacted> + 2324
13  CoreFoundation                      0x000000019be66844 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x000000019be675a8 CFRunLoopRun + 84
15  CoreMotion                          0x00000001a1964d64 CoreMotion + 507236
16  libsystem_pthread.dylib             0x000000019bae1a04 <redacted> + 132
17  libsystem_pthread.dylib             0x000000019bae1960 _pthread_start + 52
18  libsystem_pthread.dylib             0x000000019bae9df4 thread_start + 4
(lldb) 

有没有人遇到过这个问题,或者对如何解决崩溃问题有所了解?

ios swift core-motion ios12
2个回答
4
投票

好吧,我已经测试了你的应用程序,包括物理iPhone 6S和iPhone 7 - 显然是iOS 12.0.1。我还检查了你的项目中的一些东西并且根本无法重现你的问题 - 甚至在模拟器中也没有 - 我认为不可能下载具有特定修复程序(12.0.x)的模拟器,小版本更新 - 所以12.1是下一个。这看起来非常具体在iPhone XS硬件上,我建议你填写Apple support的问题。

编辑:嗯,我看到你已经填写了关于openradar的错误报告。 This guy甚至引用了openradar-mirror上的bug报告状态。


-1
投票

我对CoreMotion知之甚少,但错误消息告诉您正在尝试在后台线程上调用UI操作。尝试将您的代码放入:

DispatchQueue.main.async {
    //your code here
}

您似乎也在尝试在viewDidLoad()中执行与UI相关的操作。从技术上讲,这很好,但请记住,某些观点可能并未在那个时间点布局。

© www.soinside.com 2019 - 2024. All rights reserved.