How to automatically screen screenshots when the app enters the background

Source: Internet
Author: User
Tags password protection

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.

    • Method One:

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;
}
}

    • Method Two:

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.

    • Method Three:

You can set the Uiapplicationexitsonsuspend property in Info.plist.
Disadvantage: In the background is closed application, the limitations are relatively large.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.