在iOS 7中,当应用程序进入后台时(通过订阅UIApplicationDidEnterBackgroundNotification
),我的应用程序显示了一个身份验证屏幕。身份验证控制器删除了敏感信息,因此后台屏幕截图未显示任何用户信息。在iOS 8中,这不再起作用。后台截图现在显示用户上次工作的视图而不是身份验证控制器...即使应用程序返回到前台,身份验证控制器也处于活动状态。
我现在找到了一个工作。而不是使用UIApplicationDidEnterBackgroundNotification
我可以使用name:UIApplicationWillResignActiveNotification
但是当用户离开应用程序时这会导致闪光。
这是一个错误还是苹果提供了一种从移动到后台之前从视图中删除敏感信息的新方法。
注意:将ignoreSnapshotOnNextApplicationLaunch
放在applicationWillResignActive:
和applicationDidEnterBackground:
没有帮助。
更新:创建了错误报告
与@ Gurudev0777类似的方法,但使用UIBlurEffect来掩盖内容,并没有担心不同设备屏幕指标的缺点。申请代表:
#define MY_BACKGROUND_SCREEN_TAG 1001//or any random but UNIQUE number.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Visual effect view for blur
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
[blurView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[blurView setFrame:self.window.frame];
blurView.tag = MY_BACKGROUND_SCREEN_TAG;
[self.window addSubview:blurView];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// remove blur view if present
UIView *view = [self.window viewWithTag:MY_BACKGROUND_SCREEN_TAG];
if (view != nil)
{
[UIView animateWithDuration:0.2f animations:^{
[view setAlpha:0];
} completion:^(BOOL finished) {
[view removeFromSuperview];
}];
}
}
奇迹般有效...
2015年5月18日编辑:感谢@Simeon Rice观察模态对话框,修改后将模糊视图添加到self.window而不是rootViewController.view
2016年8月23日编辑:感谢@tpankake观察重新:自动调整大小的面具。
- (void)applicationWillResignActive:(UIApplication *)application
{
// show splash when app goto background
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
imageView.tag = 101; // assign image tag
// imageView.backgroundColor = [UIColor redColor];
[imageView setImage:[UIImage imageNamed:@"Default.png"]];
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// remove splash when app goto foreground
UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101]; // lookup image by image tag
[imageView removeFromSuperview];
}
here we are putting an imageview while the app animate to background -
-(void)applicationWillResignActive:(UIApplication *)application
{
imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
[imageView setImage:[UIImage imageNamed:@"[email protected]"]];
[self.window addSubview:imageView];
}
Here is the code to remove the imageview:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if(imageView != nil) {
[imageView removeFromSuperview];
imageView = nil;
}
}
It is working and tested many times.
*** Please test this scenario into the device not in simulator.