Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay applicationDidEnterBackground screen capture

Is there a way to delay the screen capture made by iOS when app is entering background? The reason is that I'm sometimes showing a view when the user goes to home screen I want this view removed so it doesn't show when app is resumed. The view in question is a SSHUDView (source code here) which I call dismissAnimated:NO in applicationWillResignActive. This actually works in the simulator but not on real device (the SSHUDView still shows when resuming). Anyone have a clue how to deal with this?

like image 772
Peter Warbo Avatar asked Jan 04 '13 17:01

Peter Warbo


3 Answers

I think you should handle this in applicationDidEnterBackground:.

According to Apple's documentation:

  • Prepare to have their picture taken. When the applicationDidEnterBackground: method returns, the system takes a picture of your app’s user interface and uses the resulting image for transition animations. If any views in your interface contain sensitive information, you should hide or modify those views before the applicationDidEnterBackground: method returns.
like image 156
fguchelaar Avatar answered Nov 09 '22 23:11

fguchelaar


If you have a look at the SSHUDView implementation it uses a UIWindow instance to display the content; it makes it's own UIWindow the key UIWindow:

[_hudWindow makeKeyAndVisible];

Which is probably why it's so tricky to get rid of. You might try to do what SSHUDView does after it dismisses itself to return focus to the main window:

[[[[UIApplication sharedApplication] windows] objectAtIndex:0] makeKeyWindow];

When the hud view dismissed itself it sends resignKeyWindow to it's private _hudWindow object, you could possibly try to get a handle on that before you return focus to the main window, like so:

[[[[UIApplication sharedApplication] windows] objectAtIndex:1] resignKeyWindow];

But it may cause unexpected problems because you're bypassing the SSHUDView API...

like image 2
Andrew Tetlaw Avatar answered Nov 09 '22 23:11

Andrew Tetlaw


Could you possibly get the view controller displaying the SSHUDView to listen for UIApplicationWillResignActiveNotification from [NSNotificationCenter defaultCenter] and hide it that way? Seems a little hacky, so it may not work. Just a thought.

like image 1
Adam Tootle Avatar answered Nov 09 '22 23:11

Adam Tootle