I want that my pause method is called when a push notification (push, sms) appears.
First of all, the concept of the game:
When you start the app, a main view is shown where you can choose one of three different game modes.
So, if the user plays in one game mode and gets a sms, the game should pause and if he cancels the notification, the game should go on.
the names of the viewcontrollers of the three different modes are PlayViewController, PlayTwoViewController and TimePlayViewController.
So, here’s my appDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application { [PlayViewController pauseGame]; [PlayTwoViewController pauseGame];[TimePlayViewController pauseGame]; }
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
-(void)applicationDidBecomeActive:(UIApplication *)application { [PlayViewController pauseGame]; [PlayTwoViewController pauseGame];[TimePlayViewController pauseGame]; }
- (void)applicationWillTerminate:(UIApplication *)application {
}
the pauseGame method is the always the same. The code is:
-(IBAction)pauseGame {
[myTimer invalidate];
PauseViewController *screen = [[PauseViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release]; }
myTimer is just a NSTimer.
The app crashes when I build it with the code above
The console says:
2011-04-03 11:22:10.091 appName[458:207] +[PlayViewController pauseGame]: unrecognized selector sent to class 0x1d39c
2011-04-03 11:22:10.093 appName[458:207] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[PlayViewController pauseGame]: unrecognized selector sent to class 0x1d39c’
terminate called after throwing an instance of ‘NSException’
Implement:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
“This method is called to let your application know that it is about to move from the active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. An application in the inactive state continues to run but does not dispatch incoming events to responders.
You should use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. An application in the inactive state should do minimal work while it waits to transition to either the active or background state.”