Change view before applicationWillEnterForeground

I want to block users from my application after a period of being in the background. I will catch this in the AppDelegate applicationWillEnterForeground (and compare the time stored in applicationWillResignActive ). If less than the waiting period, no action occurs. If more than the timeout, I call:

 [_navigationController popToRootViewControllerAnimated:NO]; 

which returns the user to root mode.

It works great with one visual interrupt. The previous view (that which the user viewed when the application is inactive) appears very briefly before appearing in the root. When testing, it seems that the view appears again before calling applicationWillEnterForeground .

The only thing I had was to hide everything before going inactive, for example, by shading the view with a filled rectangle. It smells like a dirty hack, so I think there is a better way.

I am also open to different ways to achieve the same end result. Thanks!

+5
source share
2 answers

I solved this by making the appearance invisible. In applicationWillResignActive, I have _navigationController.view.alpha = 0 ;, and I placed _navigationController.view.alpha = 100; in applicationWillEnterForeground after (if necessary) a login popup. Easier than popping up and restoring views (which in this case are pretty heavy).

@TheBlack indicates a hidden property, which is probably a bit simpler on the device. I leave alpha because A) it's fun debugging with a 50% alpha view, and B) I just love alpha. But if you're not an alpha fan like me, hidden might be a little better.

0
source

In the docs: Strategies for transitioning transitions in App State

Get ready for the app snapshot

Shortly after the application delegates applicationDidEnterBackground: the method returns, the system takes a snapshot of the application windows. Similarly, when an application wakes up to perform background tasks, the system can take a new snapshot to reflect any relevant changes. For example, when an application wakes up to process loaded elements, the system takes a new snapshot so that it can reflect any changes caused by the inclusion of elements. The system uses these snapshots in the multitasking interface to show the status of your application.

If you make changes to your views when you enter the background, you can call the snapshotViewAfterScreenUpdates: method of your main view to force these changes to be visualized. Calling the setNeedsDisplay method in a view is ineffective for snapshots because the snapshot is taken until the next drawing cycle, which prevents any changes from being visualized. Calling the snapshotViewAfterScreenUpdates: method with a value of YES forces the base buffers used by the snapshot engine to be updated immediately.

0
source

All Articles