ios - 在 applicationDidEnterBackground 之前显示 View 或启动画面(以避免事件 View 屏幕截图)

标签 ios background ios7 screenshot uiapplicationdelegate

我的应用程序中有 secret 信息,因此我想在应用程序即将移至后台时使用启动画面隐藏它们。

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

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

我尝试在 applicationDidEnterBackground 中显示我的 splashScreen,但它在动画期间恢复时会显示信息。

这里是我想要的精神:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [_window addSubview:__splashController.view];
}

最佳答案

我认为问题在于您正在模拟器 中进行测试。在设备上,它应该可以正常工作。

我对此进行了测试并且有效。当应用程序进入后台时,添加带有初始图像的 ImageView -

- (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) 检查时,添加的 subview 不会显示,但在设备上它按预期工作(如 paypal美国银行 应用程序)

编辑:(附加信息)

除了如上所述通过添加 subview /模糊来模糊/替换敏感信息之外,iOS 7 还让您能够通过 ignoreSnapshotOnNextApplicationLaunch 忽略屏幕快照applicationWillResignActiveapplicationDidEnterBackground 中的 UIApplication

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 中探索.

关于ios - 在 applicationDidEnterBackground 之前显示 View 或启动画面(以避免事件 View 屏幕截图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19792850/

相关文章:

ios - 后台模式下的多点连接

ios - AppDelegate 中的点击覆盖代码不起作用。如何修复这些错误?

html - CSS 水平居中背景图像然后垂直重复?

ios - 如何通过向上/向下滚动使 iOS 应用程序背景发生变化

uitableview - 永远不会满足的约束(iOS,自动布局)

ios - 绘图区域填充以防止符号被截断。 (核心剧情)

iOS 11 UITableView isEditing 标志设置不正确

css - 固定背景不工作

ios - 构建 MapView 注释非常慢

ios - 更改导航栏色调颜色 iOS 7。