我希望在出現推送通知(推送,短信)時調用我的暫停方法。推送通知出現時暫停遊戲
首先,遊戲的概念: 當您啓動應用程序時,會顯示一個主視圖,您可以在其中選擇三種不同的遊戲模式之一。 因此,如果用戶在一種遊戲模式下玩並獲得短信,遊戲應該暫停,如果他取消通知,遊戲應該繼續。
三種不同模式的viewcontrollers的名稱是PlayViewController,PlayTwoViewController和TimePlayViewController。
所以,這裏是我的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 {
}
pauseGame方法總是一樣的。代碼是:
-(IBAction)pauseGame {
[myTimer invalidate];
PauseViewController *screen = [[PauseViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release]; }
myTimer只是一個NSTimer。
應用崩潰時我的代碼生成它上面 控制檯說:
2011-04-03 11:22:10.091 APPNAME [458:207] + [PlayViewController pauseGame]:無法識別的選擇發送到class 0x1d39c 2011-04-03 11:22:10.093 appName [458:207] *因未捕獲的異常'NSInvalidArgumentException'而終止應用,原因:'+ [PlayViewController pauseGame]:無法識別的選擇器發送到類0x1d39c' 終止在拋出'NSException'實例後調用
您應該在變量上調用pauseGame - 而不是類。爲了弄清楚更多, d需要看代碼 – 2011-04-04 01:12:56
你想看更多的代碼嗎?我已經發布了我的整個應用程序委託和方法,我可以做更多的事情?我不能發佈我的應用程序的整個代碼,我應該如何調用pauseGame ,你能舉個例子嗎? – Leon 2011-04-04 16:27:08
你在哪裏發佈應用代理代碼?我看到的只是'PlayViewController pauseGame'這一行。 [PlayTwoViewController pauseGame]; [TimePlayViewController pauseGame];' 我至少需要查看完整的方法,以及pauseGame方法的定義和它們所在的類的名稱。我不能給你一個調用pauseGame的例子,因爲我不知道方法是在哪裏定義的 - 它是代碼中的東西,而不是來自iOS SDK的方法 – 2011-04-06 00:23:50