iOS UIWindow Magic (a) App password protection function

Source: Internet
Author: User
Tags password protection

We know UIWindow inherit from UIView, so uiwindow in addition to have all the functions of uiview, there are some unique property methods, the most common is that the program just started, call UIWindow makekeyandvisible make the whole program visible.

-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {

//Override point for customization after application launch.

self. window = [[UIWindowalloc]initwithframe: [uiscreen Mainscreen]. bounds ];

Viewcontroller = [[viewcontrolleralloc]init];

self. Window. Rootviewcontroller =Viewcontroller;

[self. window makekeyandvisible];

return YES;

}




So the main role of UIWindow:

1, as the top-level container for UIView, contains all the UIView required for the application display.

2. Delivering touch messages and keyboard events to UIView


Let's talk about a property that is closely related to this blog windowlevel


Uikit_extern Const Uiwindowlevel Uiwindowlevelnormal;

Uikit_extern Const Uiwindowlevel Uiwindowlevelalert;

Uikit_extern Const Uiwindowlevel Uiwindowlevelstatusbar;


Where the value of Uiwindowlevelnormal makes 0, the value of Uiwindowlevelalert is $, and the value ofUiwindowlevelstatusbar is


Let's start with the features we're going to implement today

The so-called password protection, is in the app into the background, re-enter the app when you need to enter a password access to the app password can be inconsistent with the user's login password, to protect the user's personal information, to prevent the user's phone is not around when people peek, or mobile phone lost, The leakage of sensitive information, such as the mining of wealth, there is such a function, so generally involving money, sensitive personal information of the app should have such a function

First, customize a UIWindow subclass

@interface Passwordinputwindow:UIWindow


+ (passwordinputwindow *) sharedinstance;


-(void) show;


@end


where + (passwordinputwindow *) sharedinstance; is a way to create a singleton

The specific implementation is as follows:

+ (passwordinputwindow *) sharedinstance

{

Static ID sharedinstance =nil;

Static dispatch_once_t Oncetoken;

dispatch_once (&oncetoken, ^{

Sharedinstance = [[selfalloc]initwithframe: [uiscreenmainscreen]. Bounds];

});

return sharedinstance;

}


-(void) show

{

self. Windowlevel =Uiwindowlevelalert;//top level display

[self Makekeywindow];

Self. Hidden =NO;

}


The specific demo implementation is as follows;

Demo







iOS UIWindow Magic (a) App password protection function

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.