代码:

AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//当程序在后台停留超过60分的时候,密码会置为空。 //1小时后将密码重新设置
[self timeInterval]; return YES;
} - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to 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 {
//计算时间差
[self backTime];
} - (void)applicationWillEnterForeground:(UIApplication *)application {
//1小时后将密码重新设置
[self timeInterval];
} - (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} - (void)applicationWillTerminate:(UIApplication *)application {
//计算时间差
[self backTime];
}
#pragma -mark -密码保存1个小时
//计算时间差
- (void)timeInterval
{
NSLog(@"---timeInterval----");
//设置一个字符串的时间
NSString * dateBackString = [[NSUserDefaults standardUserDefaults] objectForKey:@"backGroundTime"]; NSLog(@"---dateBackString---%@",dateBackString); if ([dateBackString isEqual:[NSNull null]] || dateBackString==nil || dateBackString.length ==0) {
}
else
{
NSInteger time = [self getTimeInterval:dateBackString];
if (time >= 60) {
//1小时后将密码清空
NSUserDefaults *userInfoDefault=[NSUserDefaults standardUserDefaults];
[userInfoDefault setObject:@"" forKey:@"login-password"];
[userInfoDefault synchronize];
}
}
}
//1小时后将密码重新设置
- (void)backTime
{ NSLog(@"----backTime-----");
//计算上报时间差
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//结束时间
NSDate * currentdate = [NSDate date];
NSString * currentDateString = [dateFormatter stringFromDate: currentdate]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:currentDateString forKey:@"backGroundTime"];
[userDefaults synchronize];
}
//计算时间差
- (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"];
//结束时间
NSDate * currentdate = [NSDate date];
NSDate * currentDate = [dateFormatter dateFromString:[dateFormatter stringFromDate: currentdate]];
NSDate * endDate = [dateFormatter dateFromString:sendDateString];
//得到时间差
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

【代码笔记】iOS-密码在进入后台1小时后重新设置的更多相关文章

  1. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  2. 支付宝APP支付IOS手机端java后台版

    版权声明:http://blog.csdn.net/u012131769/article/details/76639527#t8 转载:http://blog.csdn.net/u012131769/ ...

  3. iOS密码框实现(二)取消确定按钮

    由于将确定按钮去掉了,所以需要重新修改下代码,当输入第四个数字时,自动进入房间.   iOS 密码框效果图:     实现方式:   首先声明一个block初始化方法,因为这只是个框框,并不需要处理网 ...

  4. DW网页代码笔记

    DW网页代码笔记 1.样式.       class  插入类样式  标签技术(html)解决页面的内容样式技术(css)解决页面的外观脚本技术       解决页面动态交互问题<form> ...

  5. 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程

    一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...

  6. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

  7. 【Hadoop代码笔记】目录

    整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...

  8. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  9. <Python Text Processing with NLTK 2.0 Cookbook>代码笔记

    如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...

随机推荐

  1. tkinter之Frame

    tkinter的Frame即容器,在容器内部好像不能再嵌套一个Frame.

  2. MyBatis框架介绍及其实操

    一.基本概念和介绍 数据持久化的概念 数据持久化是将内存中的数据模型转换为存储模型,以及将存储模型转换为内存中的数据模型的统称.例如,文件的存储.数据的读取等都是数据持久化操作.数据模型可以是任何数据 ...

  3. [原创]K8 CMS GoastGuard 密码解密工具

    工具: K8 CMS GoastGuard PASS Decrypt编译: VS2012  C# (.NET Framework v4.5)组织: K8搞基大队[K8team]作者: K8拉登哥哥博客 ...

  4. 基于alpine用dockerfile创建的nginx镜像

    1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...

  5. 遗忘Windows Server 2008R2密码的处理方法

    遗忘Windows Server 2008R2的处理方法 有的时候,我们会由于各种原因忘掉了服务器密码,比如服务器太多,太杂什么的,或直接是被人黑掉了,这个时候我们想要登录,发现我们已经没有办法了,其 ...

  6. Oracle 获取本周、本月、本季、本年的第一天和最后一天

    Oracle 获取本周.本月.本季.本年的第一天和最后一天 --本周 select trunc(sysdate, 'd') + 1 from dual; select trunc(sysdate, ' ...

  7. C# 多线程五之Task(任务)一

    1.简介 为什么MS要推出Task,而不推Thread和ThreadPool,以下是我的见解: (1).Thread的Api并不靠谱,甚至MS自己都不推荐,原因,它将整个Thread类都不开放给Win ...

  8. 全网最全的Windows下Python2 / Python3里正确下载安装用来向微信好友发送消息的itchat库(图文详解)

    不多说,直接上干货! 建议,你用Anaconda2或Anaconda3. 见 全网最全的Windows下Anaconda2 / Anaconda3里正确下载安装用来向微信好友发送消息的itchat库( ...

  9. php -- 数据库信息

    ----- 023-dbinfo.php ----- <!DOCTYPE html> <html> <head> <meta http-equiv=" ...

  10. JavaScript初探三

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...