在didFinishLaunchingWithOptions方法里添加以下代码,可以禁止系统读取应用快照,这样应用在进入后台后,按下Home键显示的应用快照是纯黑的,可以避免信息泄露。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 13.0,*)) {
NSString * path = [NSString stringWithFormat:@"%@/Library/SplashBoard/Snapshots", NSHomeDirectory()];
NSError * error = nil;
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
if (error != nil) {
NSLog(@"%@", error);
}
[[NSFileManager defaultManager] setAttributes:@{ NSFilePosixPermissions : @(0444) } ofItemAtPath:path error:&error];
if (error != nil) {
NSLog(@"%@", error);
}
} else {
NSString * path = [NSString stringWithFormat:@"%@/Library/Caches/Snapshots", NSHomeDirectory()];
NSError * error = nil;
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
if (error != nil) {
NSLog(@"%@", error);
}
[[NSFileManager defaultManager] setAttributes:@{ NSFilePosixPermissions : @(0444) } ofItemAtPath:path error:&error];
if (error != nil) {
NSLog(@"%@", error);
}
}
return YES;
}