5
장치 동작 (피치, 롤, 요우)을 얻으려고 시도했지만 내 기능 handleDeviceMotionUpdate가 시작되지 않았습니다 (iphone 5s에서 시도 함). 여기 코드는동작 관리자가 작동하지 않음
입니다.import UIKit
import CoreMotion
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var motionManager = CMMotionManager()
motionManager.startDeviceMotionUpdates()
motionManager.deviceMotionUpdateInterval = 0.1
motionManager.startDeviceMotionUpdatesToQueue(
NSOperationQueue.currentQueue()!, withHandler: {
(deviceMotion, error) -> Void in
if(error == nil) {
self.DeviceMotionUpdate(deviceMotion!)
} else {
print("error")
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func DeviceMotionUpdate(deviceMotion:CMDeviceMotion) {
print("function launched")
var attitude = deviceMotion.attitude
var roll = (attitude.roll)
var pitch = (attitude.pitch)
var yaw = (attitude.yaw)
print("Roll: \(roll), Pitch: \(pitch), Yaw: (yaw)")
}
}
startDeviceMotionUpdatesToQueue에 오류가 표시되지 않습니다. motionManager.deviceMotionActive 및 motionManager.deviceMotionAvailable에 대해 설명합니다.
감사합니다. – Theilya