显示applicationDidEnterBackground前视图或闪屏(以避免活动视图截图) [英] Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)
问题描述
我在我的应用程序的机密信息,所以我想将它们隐藏了闪屏时,应用程序将要被转移到后台。
我做的运行iOS6的应用程序,并进一步。
我试着显示 applicationWillResignActive
的观点,但问题是,它显示启动画面,即使例如用户刷卡控制面板。我想让它显示只有当应用程序移动到后台。
我试着在 applicationDidEnterBackground
显示我的启动画面,但它需要截图之前,所以信息是在恢复过程中的动画显示。
下面的我想要什么精神:
- (无效)applicationDidEnterBackground:(UIApplication的*){应用
[_window addSubview:__ splashController.view];
}
我认为问题是,你在模拟器测试。在设备上,它应该很好地工作。
我测试了这一点,它的工作。添加ImageView的与你的闪屏图像时,应用程序在后台进入 -
- (无效)applicationDidEnterBackground:(UIApplication的*)的应用
{ * UIImageView的ImageView的= [[UIImageView的页头] initWithFrame:方法self.window.bounds]; imageView.tag = 101; //给一些体面tagvalue或保持在一个自我的ImageView的引用
// imageView.backgroundColor =的UIColor redColor]
[ImageView的setImage:[UIImage的imageNamed:@为Default.png]]; //假设为Default.png是你的闪屏图像的名字 [UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:ImageView的]。
}
和应用程序的时候回来在前台 -
- (无效)applicationWillEnterForeground:(UIApplication的*)的应用
{
*的UIImageView = ImageView的(UIImageView的*)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101] //用相同的标记值搜索
[ImageView的removeFromSuperview]}
请注意 - 在模拟器(的iOS 7.0),添加的子视图是不是当你通过pressing home键两次(Cmd的+ H)检查显示,但在设备,它工作正常(如贝宝
,美国银行
应用程序)
编辑:(附加信息)
除了模糊/加子视图代替敏感信息/模糊如上所述,的iOS 7 为您提供忽略通过 ignoreSnapshotOnNextApplicationLaunch $ C $屏幕快照能力C>
的UIApplication
里面的 applicationWillResignActive
或 applicationDidEnterBackground
。
的 UIApplication.h 的
//指明应用程序不应使用快照在下次启动,即使有一个有效的状态恢复存档。
//这应该只从国家preservation调用的方法被调用,否则将被忽略。
- (无效)ignoreSnapshotOnNextApplicationLaunch NS_AVAILABLE_IOS(7_0);
此外, allowScreenShot
标记可以探索<一个href=\"https://developer.apple.com/library/ios/featuredarticles/iPhoneConfigurationProfileRef/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010206-CH1-SW13\">Restrictions有效载荷。
I have confidential informations in my app, so I would like to hide them with a splash screen when the app is about to be moved to background.
I do run the app on iOS6 and further.
I tried to display the view in applicationWillResignActive
but the problem is it display the splash screen even when user swipe control panel for example. I want it to show only when the app is moved to background.
I tried to displayed my splashScreen in applicationDidEnterBackground
but it takes the screenShot before so informations are displayed at restoration during the animation.
Here the spirit of what I want :
- (void)applicationDidEnterBackground:(UIApplication *)application {
[_window addSubview:__splashController.view];
}
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.
这篇关于显示applicationDidEnterBackground前视图或闪屏(以避免活动视图截图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!