Swift の AppDelegate (アプリ全体) でデバイスの揺れを検出するにはどうすればよいですか?
ビューコントローラーでこれを行う方法を説明する回答を見つけましたが、アプリ全体でそうしようとしています。
Swift の AppDelegate (アプリ全体) でデバイスの揺れを検出するにはどうすればよいですか?
ビューコントローラーでこれを行う方法を説明する回答を見つけましたが、アプリ全体でそうしようとしています。
に次のスニペットを追加しますAppDelegate
。
override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent?) {
if motion == .MotionShake {
print("Device shaken")
}
}
スウィフト 3.0 バージョン:
override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
if motion == .motionShake {
print("Device shaken")
}
}