5
Próbuję uzyskać ruch urządzenia (pitch, roll, yaw), ale moja funkcja handleDeviceMotionUpdate nie jest uruchomiona (próbuję go na iPhone 5s), tutaj jest kod:Menedżer ruchu nie działa
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)")
}
}
Nie otrzymuję błąd w StartDeviceMotionUpdatesToQueue. Realizuję się na motionManager.deviceMotionActive i na motionManager.deviceMotionAvailable
O, dziękuję, zadziałało! – Theilya