Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)
I think the problem is that you are testing in simulator. On device, it should work fine.
I tested this and it worked. Add an imageview with your splash image when app enters in background -
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
imageView.tag = 101; // Give some decent tagvalue or keep a reference of imageView in self
// imageView.backgroundColor = [UIColor redColor];
[imageView setImage:[UIImage imageNamed:@"Default.png"]]; // assuming Default.png is your splash image's name
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}
And when app comes back in foreground -
- (void)applicationWillEnterForeground:(UIApplication *)application
{
UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101]; // search by the same tag value
[imageView removeFromSuperview];
}
NOTE - On simulator (iOS 7.0), the added subview is not show when you check by pressing home button twice (Cmd + H), but on device it works as expected (like paypal
, BofA
apps)
EDIT: (Additional info)
In addition to obscuring/replacing sensitive information by adding subview / blur as explained above, iOS 7 provides you ability to ignore the screen snapshot via ignoreSnapshotOnNextApplicationLaunch
of UIApplication
inside applicationWillResignActive
or applicationDidEnterBackground
.
UIApplication.h
// Indicate the application should not use the snapshot on next launch, even if there is a valid state restoration archive.
// This should only be called from methods invoked from State Preservation, else it is ignored.
- (void)ignoreSnapshotOnNextApplicationLaunch NS_AVAILABLE_IOS(7_0);
Also, allowScreenShot
flag can be explored in Restrictions Payload.
View added in applicationDidEnterBackground not visible until app returns from background
When the applicationDidEnterBackground method returns, a snapshot of the current view of the app is taken to be used for the multitasking view. The reason that you are not seeing the update is because the snapshot is taken before the drawing cycle. Even if you call setNeedsDisplay the snapshot still is taken before.
To wait until the view updates (after you have added your subview) call this:
[self.view snapshotViewAfterScreenUpdates:YES];
with a value of YES
. This forces your changes to render first. You can read more about handling stuff like this in apple docs here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW27
Prevent Splash Screen from showing after returning from background
Well, apparently this question wasn't very clever to begin with :)
This "problem" only happens in the Simulator. When Debugging on the device itself, it works as expected.
No harm done. Thanks everyone who tried to help! :)
Delay applicationDidEnterBackground screen capture
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...
Hide UI after resigning application
From the iOS App Programming Guide
What to Do When Moving to the Background
Apps can use their applicationDidEnterBackground: method to prepare
for moving to the background state. When moving to the background, all
apps should do the following:
- 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.
So, in your applicationDidEnterBackground
method you should hide your main view and present your 'login' view.
Update After a bit more research, it turns out you can't present a view controller - you can only affect the root window. I have tested the solution in this answer - Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot) and it works - So you can create an image that shows your login screen and put that over the top of your UI.
Security-Active Application in background-Does it store image of current screen
Most financial apps (like paypal, BofA) which seeks security in such case address this issue by adding a view or blur'ing the active view when app applicationDidEnterBackground
and restore the original state when applicationWillEnterForeground
of UIApplicationDelegate
.
Here is another linked question.
Preventing snapshot view of your app when coming back from multi-tasking
I solved this. Here is the solution:
- (void)applicationDidEnterBackground:(UIApplication *)application{
if (appHasPasscodeOn){
UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[window addSubview:splashView];
[splashView release];
}
}
Default.png is a screenshot of my app with a blank screen (for me it's just a blank listview). The code above puts that in front of my real view right before the app goes into the background. So, when you come back to the app that is all you see. Voila.
Related Topics
Renew Push Certificate and Keep Current App Store App Working
Xcode 9 - "Fixed Width Constraints May Cause Clipping" and Other Localization Warnings
Dynamic Cell Width of Uicollectionview Depending on Label Width
How to Detect Network Signal Strength in iOS Reachability
Uicollectionview: Must Be Initialized with a Non-Nil Layout Parameter
Detecting Collisions in Sprite Kit
How to Achieve a "Clock Wipe"/ Radial Wipe Effect in iOS
How to Create a Scroll View with a Page Control Using Swift
Check If a Uiscrollview Reached the Top or Bottom
Loading an Image into Uiimage Asynchronously
Capturing and Storing a Picture Taken with the Camera into a Local Database/Phonegap/Cordova/Ios
Uidatepicker Select Month and Year
Custom Init for Uiviewcontroller in Swift with Interface Setup in Storyboard
Place Images Along a Bezier Path
Store [String] in Nsuserdefaults