"Code Note" ios-password is reset after 1 hours into the background

Source: Internet
Author: User

Code:

Appdelegate.m

#import"AppDelegate.h"#import"ViewController.h"@interfaceAppdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (NSDictionary *) Launchoptions {//Override point for customization after application launch.//When the program stays in the background for more than 60 minutes, the password is set to empty.//Reset the password after 1 hours[Self timeinterval];ReturnYES;} - (void) Applicationwillresignactive: (UIApplication *) Application {//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state.//Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void) Applicationdidenterbackground: (UIApplication *) Application {//Calculate Time Difference[Self backtime];} - (void) Applicationwillenterforeground: (UIApplication *) Application {//Reset the password after 1 hours[Self timeinterval];} - (void) Applicationdidbecomeactive: (UIApplication *) Application {//Restart any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.}- (void) Applicationwillterminate: (UIApplication *) Application {//Calculate Time Difference[Self backtime];}#pragma-mark-Password save 1 hours//Calculate the time Difference-(void) timeinterval{NSLog (@"---timeinterval----");//Set the time of a string NSString * datebackstring = [[Nsuserdefaults standarduserdefaults] Objectforkey:@"Backgroundtime"]; NSLog (@"---datebackstring---%@", datebackstring);if ([Datebackstring isequal:[nsnullNULL]] | | Datebackstring==nil | | Datebackstring.length = =0) { }Else{Nsinteger time =[Self gettimeinterval:datebackstring];if (Time >=60) {//Empty the password after 1 hours nsuserdefaults *userinfodefault=[Nsuserdefaults Standarduserdefaults]; [Userinfodefault SetObject:@ "" Forkey:@"Login-password"]; [Userinfodefault Synchronize]; } }}//Reset the password after 1 hours-(void) backtime{NSLog (@"----Backtime-----");//Calculate escalation time difference nsdateformatter *dateformatter =[[NSDateFormatter alloc] init]; [Dateformatter Setdateformat:@"YYYY-MM-DD HH:mm:ss"];//End time NSDate * currentdate =[NSDate Date]; NSString * currentdatestring =[Dateformatter Stringfromdate:currentdate]; Nsuserdefaults *userdefaults =[Nsuserdefaults Standarduserdefaults]; [Userdefaults setobject:currentdatestring Forkey:@"Backgroundtime"]; [Userdefaults synchronize];}//Calculate Time Difference-(Nsinteger) Gettimeinterval: (NSString *) senddatestring{Nsinteger minute;if (senddatestring ==nil| | senddatestring.length==0) { }Else{NSDateFormatter *dateformatter =[[NSDateFormatter alloc] init]; [Dateformatter Setdateformat:@"YYYY-MM-DD HH:mm:ss"];//End time NSDate * currentdate =[NSDate Date]; NSDate * currentdate = [dateformatter Datefromstring:[dateformatter stringfromdate:currentdate]; NSDate * endDate = [dateformatter datefromstring:senddatestring]; // get time difference nstimeinterval time = [currentdate Timeintervalsincedate:enddate]; // int days = ((int) time)/(3600*24); // int hours = ((int) time)% (3600*24)/3600; // minute = ((nsinteger) time)% (3600*24)/3600/60; minute =  (Nsinteger) time;} return minute;}  @end             

"Code Note" ios-password is reset after 1 hours into the background

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.