ios - ignoreSnapshotOnNextApplicationLaunch() 未按预期工作

标签 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()

有什么帮助吗? 🙏

最佳答案

我尝试在每种可能的方法中调用ignoreSnapshotOnNextApplicationLaunch,但对我来说它仍然无法正常工作。

相反,我最终使用了虚假的启动图像来阻止用户看到真实的应用内容:

- (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 方法)

关于ios - ignoreSnapshotOnNextApplicationLaunch() 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55129249/

相关文章:

ios - 在 View Controller 之间传递数据

ios - 在测试设备上部署 iOS 应用程序。应用不包含某些图像

ios - 为什么我会收到此委托(delegate)代码的错误?

ios - 架构 arm64 的 undefined symbol : "_OBJC_CLASS_$_RadioUIButton"

ios - Xcode 更新到 7.3 后断言失败

ios - UITableView header 中容器 View 的高度错误

ios - AudioKit 4.1 - 如何正确停止 AKSampler 播放音频?

ios - 无法使用代码从 xcassets 加载图像,但 xib 可以

xcode - 模拟器中的黑屏问题

iphone - EGORefreshTableHeaderView 检查连接