gpt4 book ai didi

ios - 当CMMotionManager回调 'startDeviceMotionUpdatesToQueue'时应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 19:15:23 25 4
gpt4 key购买 nike

在我的项目中,我使用了CoreMotion,我的代码在img中。有时它会崩溃,但我不能重复它,我也不知道为什么..有人可以帮助我吗?我被它折磨了好久了……

启动 Action 管理器:

enter image description here

handler

crash]

最佳答案

Please try this code

import CoreMotion

var motionManager: CMMotionManager?

override func viewDidLoad() {
super.viewDidLoad()
motionManager = CMMotionManager()
if motionManager?.isDeviceMotionAvailable == true {

motionManager?.deviceMotionUpdateInterval = 0.1;

let queue = OperationQueue()
motionManager?.startDeviceMotionUpdates(to: queue, withHandler: { [weak self] (motion, error) -> Void in

// Get the attitude of the device
if let attitude = motion?.attitude {
// Get the pitch (in radians) and convert to degrees.
// Import Darwin to get M_PI in Swift
print(attitude.pitch * 180.0/M_PI)
}
})

print("Device motion started")
}
else {
print("Device motion unavailable");
}
// Do any additional setup after loading the view, typically from a nib.
}


based on attitude.pitch you can know Device angle and rotation on ( + & - )

关于ios - 当CMMotionManager回调 'startDeviceMotionUpdatesToQueue'时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50462133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com