When you click the Home button to bring the app into the background, iOS automatically screenshots the current screen and saves it as a picture file.
As you can see in your Mac, these screenshots are saved in the following path:
And the file name begins with "uiapplicationautomaticsnapshotdefault-".
These automatically generated screenshots are a serious security issue for applications that have password-protected functionality enabled.
After a variety of tests, 3 solutions were found.
After debugging, the screenshot processing occurs after Applicationdidenterbackground is executed (that is, when the home key is clicked).
1. Click the Home button
Will execute Applicationwillresignactive-applicationdidenterbackground, in turn
2. Double-click Home or four-point swipe
Execute applicationwillresignactive only
According to the above debugging results, the following processing can be done in appdelegate:
-(void) Applicationwillresignactive: (uiapplication *) application
{
If password protection is enabled, add a temporary blank screen to obscure the current display
if (Usepin)
{
if (Self.lockview)
{
[Self.lockview Removefromsuperview];
Self.lockview = nil;
}
Self.lockview = [[[UIView alloc] initWithFrame:self.window.bounds] autorelease];
Self.lockView.backgroundColor = [Uicolor Graycolor];
[Self.window AddSubview:self.lockView];
}
}
-(void) Applicationdidenterbackground: (uiapplication *) application
{
Hides the current window, you can suppress the screenshot, or make the resulting screenshot file a blank file
Self.window.hidden = YES;
}
-(void) Applicationdidbecomeactive: (uiapplication *) application
{
Show window
if ([Self.window Ishidden])
{
Self.window.hidden = NO;
}
Add your password input screen here
if (Usepin)
{
TODO: Set Password input screen
}
Delete temporary screen
if (Self.lockview)
{
[Self.lockview Removefromsuperview];
Self.lockview = nil;
}
}
Call UIApplication's ignoresnapshotonnextapplicationlaunch.
Since this method only appears after iOS SDK 7.0, unable to solve the screenshot problem in IOS6, give up decisively.
You can set the Uiapplicationexitsonsuspend property in Info.plist.
Disadvantage: In the background is closed application, the limitations are relatively large.