Add the following snippet to AppDelegate :
override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent?) { if motion == .MotionShake { print("Device shaken") } }
Swift version 3.0:
override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) { if motion == .motionShake { print("Device shaken") } }
For later versions, this no longer works. You need to add the above code to your view controller
source share