在 applicationDidEnterBackground 之前显示视图或启动屏幕(以避免活动视图屏幕截图) [英] Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)

查看:33
本文介绍了在 applicationDidEnterBackground 之前显示视图或启动屏幕(以避免活动视图屏幕截图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有机密信息,所以我想在应用即将移至后台时用启动屏幕隐藏它们.

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.

我确实在 iOS6 及更高版本上运行该应用程序.

I do run the app on iOS6 and further.

我试图在 applicationWillResignActive 中显示视图,但问题是即使用户滑动控制面板,它也会显示启动画面.我希望它仅在应用移至后台时显示.

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.

我尝试在 applicationDidEnterBackground 中显示我的 splashScreen,但它需要先截屏,因此在动画期间恢复时会显示信息.

I tried to displayed my splashScreen in applicationDidEnterBackground but it takes the screenShot before so informations are displayed at restoration during the animation.

这里是我想要的精神:

- (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];
}

当应用返回前台时 -

- (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) 进行检查时,不会显示添加的子视图,但在设备上它按预期工作(如 paypalBofA 应用程序)

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)

(附加信息)

除了如上所述通过添加子视图/模糊来隐藏/替换敏感信息外,iOS 7 还提供了通过 ignoreSnapshotOnNextApplicationLaunch 忽略屏幕快照的功能applicationWillResignActiveapplicationDidEnterBackground 内的 UIApplication.

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);

此外,allowScreenShot 标志可以在 限制负载.

Also, allowScreenShot flag can be explored in Restrictions Payload.

这篇关于在 applicationDidEnterBackground 之前显示视图或启动屏幕(以避免活动视图屏幕截图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆