1

I have the following swift code and I tried to test whether the CMMotionManager is working, but every time I use the shake gesture on simulator, the result is not what I expect but a undo tying notification.

let manager = CMMotionManager()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    if manager.deviceMotionAvailable {
        manager.deviceMotionUpdateInterval = 0.02
        manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
            [weak self] (data: CMDeviceMotion?, error: NSError?) in

            if data?.userAcceleration.x < -2.5 {
                self?.resLabel.text = "Shaked"
            }
        }
    }
}
Joey Zhang
  • 363
  • 6
  • 18

1 Answers1

2

The simulator does not simulate any motion. You have to use a physical device to test anything with CMMotionManager.

SeanRobinson159
  • 894
  • 10
  • 19