Can I get a message when I show UIAlertView

I want to receive a message when the system displays a UIAlertView so that I can pause my game.

Does anyone know how to figure this out?

UIAlertView is not controlled by me.

+2
source share
4 answers

application delegate applicationWillResignActive: will be called on interrupts. You can handle this pause, or you can even listen to UIApplicationWillResignActiveNotification in your view controller and pause the game there.

You can see this part the iOS Application Guide, which describes the application life cycle and state transition.

+2
source

A system warning is usually displayed in its own UIWindow . Set up handlers for notifications UIWindowDidBecomeVisibleNotification and UIWindowDidBecomeHiddenNotification to track when the UIWindow becomes visible and hidden respectively:

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aWindowBecameVisible:) name:UIWindowDidBecomeVisibleNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aWindowBecameHidden:) name:UIWindowDidBecomeHiddenNotification object:nil]; 

In the handlers, take UIWindow , which will change the state from the object property of the notification:

 - (void)aWindowBecameVisible:(NSNotification *)notification { UIWindow *theWindow = [notification object]; NSLog(@"Window just shown: %@", theWindow); } - (void)aWindowBecameHidden:(NSNotification *)notification { UIWindow *theWindow = [notification object]; NSLog(@"Window just hidden: %@", theWindow); } 

Finally, make sure that theWindow contains a sub-item of type UIAlertView .

+7
source

If your UIAlertView is associated with a third-party application (and not with your application), you can implement the delegation methods below to pause and resume the game.

To pause the game

 - (void)applicationWillResignActive:(UIApplication *)application { } 

To resume the game

 - (void)applicationDidBecomeActive:(UIApplication *)application { } 

For example, if you receive a call or SMS, you can use the above delegate to pause / resume the game.

+1
source

Just do the following:

 - (void)applicationWillResignActive:(UIApplication *)application { //pause } - (void)applicationDidBecomeActive:(UIApplication *)application { //resume } 
0
source

Source: https://habr.com/ru/post/898864/


All Articles