MotionEnded not called in appDelegate

I want to integrate the shake function throughout the application. Therefore, I do everything in appDelegate. I need to click viewController, I can click in motionBegan, but I wanted to make it motionEnded. yes motion finished works in the view controller, but in application deletion it is not called. Performance

- (void)applicationDidBecomeActive:(UIApplication *)application { [self becomeFirstResponder]; } - (BOOL)canBecomeFirstResponder{ return YES; } 

motionEnded is not called

 -(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if(event.subtype==UIEventSubtypeMotionShake){ NSLog(@"motionEnded called"); } } 

motionBegan called

 -(void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if(event.subtype==UIEventSubtypeMotionShake){ NSLog(@"motionBegan called"); } } 
+4
source share
1 answer

you can basically register your viewController for applicationDidBecomeActiveNotification or any depending on your needs

for example, in your viewController viewDidLoad method, you can register it for notification

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:UIApplicationDidBecomeActiveNotification object:nil]; 

and implement this method in your class, your myMethod will call every time your application becomes active

 -(void) myMethod(){ // do your stuff } 

permanently remove the viewController register from the notification in the dealloc method

 -(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } 
+1
source

All Articles