5
votes

I want to integrate shake feature throughout the app. So I am doing everything in appDelegate. I need to push a viewController, I am able to push in motionBegan, but i wanted to do it motionEnded. yes motion ended does work in a view controller, but in app delegate it is not being called. Doing as

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

motionEnded 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");
    }
}
1
posting notification could help I guess - nsgulliver
i havenot worked that much with notification i tried addingObserver "DeviceShaken" in applicationDidBecomeActivie but no gain - Raheel Sadiq
did you solve your issue? was answer helpful? - nsgulliver
i am moved to some other part of the project, the answer was gud so i upvote, i will let you know when i get on this issue and will mark it the right answer if it is. - Raheel Sadiq

1 Answers

1
votes

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

for example in your viewController's viewDidLoad method you could 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 everytime your application will become active

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

finally un-register viewController from the notification in dealloc method

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