代码:

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. 10-02 Java 形式参数和返回值的问题深入研究,链式编程

    形式参数和返回值的问题: 1:形式参数和返回值的问题(理解) (1)形式参数: 类名:需要该类的对象 抽象类名:需要该类的子类对象 接口名:需要该接口的实现类对象 (2)返回值类型: 类名:返回的是该 ...

  2. mysql添加类似oracle的伪列及查看表信息

    sql格式: AS rownum, table_name.* ) r, table_name; AS rownum, table_name.字段1, table_name.字段2, table_nam ...

  3. odoo开发笔记--模型字段compute用法

    compute属性,实现的主要功能是,前端界面选择某个字段的时候,指定与该字段关联的其他字段可以关联,并联动的显示. 可以和inverse属性同时使用,不加inverse属性的话,前端界面的显示效果只 ...

  4. 基于GTK+3 开发远程控制管理软件(C语言实现)系列 一 开篇

    近期趁公司没项目来,想学习一下C和GTK+3 ,顺道再学习一下Linux下有关网络编程方面的知识. 一.学习知识: 1.C基本语法 2.GTK+3 API学习 GUI相关知识学习 3.Glade使用及 ...

  5. C# 字符串操作详解

    MSDN关于String的所有Method 1.字符串转字符数组 (1).ToCharArray()方法,源码如下: 调用代码: var str = "Hello World"; ...

  6. LSP劫持症状及解决方案

    [症状] 1.网络连接正常,win7诊断显示无问题,但打开网页很迅速的显示该页无法显示,好像浏览器并没有提交任何url就做出了反应一样,输入其他网址,有时候也出现等候很久最终也是无法上网,firefo ...

  7. ES6常用语法总结

    ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015.也就是说,ES6就是ES2015.虽 ...

  8. 轻量级web富文本框——wangEditor使用手册(3)——如何自定义配置菜单 demo

    最新版wangEditor: 配置说明:http://www.wangeditor.com/doc.html demo演示:http://www.wangeditor.com/wangEditor/d ...

  9. postman参数化 接口响应数据获取符合条件的内容参数化给后面的接口使用

    一:主要内容 从响应结果中找到满足条件的key,获取其value,参数化给后面的接口使用 二:参数化获取想要的value值,传给后面的接口使用 有时我们获取的响应数据,需要的那个字段可能在一个数组里面 ...

  10. 最短路径算法----Dijkstra (转)

    Dijkstra算法的核心思想是贪心策略+动态规划 算法流程: 在以下说明中,s为源,w[u,v]为点u和v之间的边的长度,结果保存在dis[] 初始化:源的距离dis[s]设为0,其他的点距离设为无 ...