我正在尝试使用 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/