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.
Swift 3.0 Answer for those who are to lazy to translate.
func applicationDidEnterBackground(_ application: UIApplication) { let imageView = UIImageView(frame: self.window!.bounds) imageView.tag = 101 imageView.image = ... UIApplication.shared.keyWindow?.subviews.last?.addSubview(imageView) }func applicationWillEnterForeground(_ application: UIApplication) { if let imageView : UIImageView = UIApplication.shared.keyWindow?.subviews.last?.viewWithTag(101) as? UIImageView { imageView.removeFromSuperview() }}
Had the same issue, essentially I was using applicationDidEnterBackground
to show a UIWindow on top of the content, but in iOS8 it didn't work as it did in iOS7.
The solution I found was to create the UIWindow in applicationWillResignActive
but make it hidden securityWindow.hidden = YES
; and then in applicationDidEnterBackground
all I would do would be to change securityWindow.hidden = NO
.
This seems to work exactly as iOS7 obscuring the content when multi tasking without affecting the view when using NotificationCenter or ControlPanel.