ignoreSnapshotOnNextApplicationLaunch()无法正常工作

时间:2019-03-12 19:23:18

标签: ios swift xcode

我正在尝试使用https://developer.apple.com/documentation/uikit/uiapplication/1623097-ignoresnapshotonnextapplicationl中记录的ignoreSnapshotOnNextApplicationLaunch()方法“防止应用程序在下一个启动周期内使用最新的快照图像”

Apple非常明确地说:“您必须在用于保存应用状态的代码中调用此方法。”

我从每个可能的保存和恢复方法中调用此方法都没有成功。包括App screen snapshot being shown instead of launchScreen during state restoration

中提到的encodeRestorableStateWithCoder()

有帮助吗?

1 个答案:

答案 0 :(得分:0)

我试图通过各种可能的方法调用ignoreSnapshotOnNextApplicationLaunch,但对我来说似乎还是很麻烦。

相反,我最终使用了伪造的启动图像,以防止用户看到真实的App内容:

- (void)applicationWillResignActive:(UIApplication *)application {
  // This line doesn't seem to work...
  // [application ignoreSnapshotOnNextApplicationLaunch];

  self.appCover = [[UIImageView alloc] initWithFrame:[self.window frame]];
  // setup a little in order to make our fake looks better
  self.appCover.contentMode = UIViewContentModeScaleAspectFit;
  self.appCover.backgroundColor = [UIColor whiteColor];
  // This is the image we use in our LaunchScreen.xib
  [self.appCover setImage:[UIImage imageNamed:@"LaunchImage"]];
  [self.window addSubview:self.appCover];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
  // get rid of the fake launch image after App become active
  if (self.appCover) {
    [self.appCover removeFromSuperview];
    self.appCover = nil;
  }
}

并不完美,但其工作方式类似于ignoreSnapshotOnNextApplicationLaunch


2019-04-11更新:

这真令人尴尬:事实证明,由于某些第三方框架未正确发布,我的应用每次在-[UIApplication terminateWithSuccess]之后崩溃。

因此,就我而言,我只需要在applicationWillTerminate中正确释放这些框架,一切就可以按预期进行。 (甚至不需要ignoreSnapshotOnNextApplicationLaunch方法)