我在我的应用程序中集成了震动识别功能。我已将它放在我的 appdelegate 中,以便能够在整个应用程序中使用它。它在 iOS 5 上运行良好,但在 iOS 4 上却不起作用。
我在我的 appdelegate.m 中使用以下代码:
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self becomeFirstResponder];
....
}
-(BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"motionBegan");
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"motionEnded");
}
如果我在 iOS5 模拟器中运行它并激活摇动手势,我会收到 NSLog 消息。如果我在 iOS 4.3 模拟器中运行它,它就不起作用。与真实设备相同。