我认为问题在于您正在模拟器中进行测试。在设备上,它应该可以正常工作。
我对此进行了测试,并且有效。当应用程序进入后台时,添加带有初始图像的图像视图 -
- (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];
}
当应用程序回到前台时 -
- (void)applicationWillEnterForeground:(UIApplication *)application
{
UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101]; // search by the same tag value
[imageView removeFromSuperview];
}
注意 - 在模拟器(iOS 7.0)上,当您按两次主页按钮(Cmd + H)进行检查时,不会显示添加的子视图,但在设备上它可以按预期工作(例如paypal
,BofA
应用程序)
编辑:(附加信息)
除了如上所述通过添加子视图/模糊来隐藏/替换敏感信息之外,iOS 7ignoreSnapshotOnNextApplicationLaunch
还为您提供了通过UIApplication
insideapplicationWillResignActive
或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);
此外,allowScreenShot
可以在Restrictions Payload中探索标志。