Reputation: 121
im trying to apply a method in this method from a view controller in my game when a call received to pause the game.
- (void)applicationWillResignActive:(UIApplication *)application
any idea?
Upvotes: 0
Views: 2467
Reputation: 4162
The other answers are correct in that -applicationWillResignActive:
is called on the application delegate so you just have to have that method written in your delegate to respond to that event. However if you want to write code in your view controller to listen for this event you can register for the UIApplicationWillResignActiveNotification
from your view controller. For example:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(pauseGame:)
name:UIApplicationWillResignActiveNotification
object:nil];
See Apple Documentation search for UIApplicationWillResignActiveNotification.
Upvotes: 3
Reputation:
This is a method from UIApplicationDelegate protocol and it must be called in your application Delegate class when the screen locks or an incoming call is received. You should not call this method by yourself
Upvotes: 1
Reputation: 1522
applicationWillResignActive is called by iOS when your app is going to be interrupted, you shouldn't be calling it by yourself.
if you'd like to have some pausing logic for when you app goes to background you should implement it in you delegates -applicationWillResignActive:
or -applicationWillEnterForeground:
Upvotes: 0