代码:

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. CentOS7安装MYSQL。

    参考这个文章(网页已存到本地):http://www.cnblogs.com/starof/p/4680083.html 安装完成后,本地登录MYSQL没有问题. 现在主要是在windows下用ora ...

  2. Failed to start docker.service: Unit not found.

    安装教程参考: https://docs.docker.com/install/linux/docker-ce/centos/#install-docker-ce-1 https://yq.aliyu ...

  3. cFSMN和FSMN参数规模对比分析

    1. FSMN参数规模分析        (1)分析前提: 假设隐藏层单元规模都为n 只分析前向t个时刻的结构,即暂时不考虑双向的结构 只分析向量系数编码,即vFSMN,暂时不考虑sFSMN     ...

  4. 【sping揭秘】4、某些无法注册到IOC容器的对象如何交给spring托管

    可以实现spring的factoryBean 接口,这样可以加入spring的IOC容器 比如现在有一个类叫MyObject,我们没有这个对象的源码,无法对这个对象进行操作,那么我们如何加入sprin ...

  5. C#枚举中使用Flags特性

    .NET中的枚举我们一般有两种用法,一是表示唯一的元素序列:还有就是用来表示多种复合的状态.这个时候一般需要为枚举加上[Flags]特性标记为位域,这样我们就可以用"或"运算符组合 ...

  6. django2笔记:路由path语法

    django2笔记:路由path语法 9月23,Django 发布了2.0a1版本,这是一个 feature freeze 版本,如果没有什么意外的话,2.0正式版不会再增加新的功能了.按照以往的规律 ...

  7. 整理几个 RPC 框架

    gRPChttp://www.grpc.io/https://github.com/grpcMotan支撑微博千亿调用的轻量级RPC框架:Motanhttp://h2ex.com/820WangleW ...

  8. MySQL问答整理

    1.Mysql中有哪些不同的表格? MyISAM: 基于IASM代码.可以被压缩,支持全文搜索,事务不安全,而且也不支持外键.如果事务回滚将会造成不完全回滚,从而不具备原子性.所以假如忽略事务以及访问 ...

  9. 百度前端技术学院-task2.18-2.19源码以及个人总结

    源码:http://yun.baidu.com/share/link?shareid=2310452098&uk=1997604551 1.感觉在写js的时候,最好先理清思路,先干什么,在干什 ...

  10. 【learning】多项式开根详解+模板

    概述 多项式开跟是一个非常重要的知识点,许多多项式题目都要用到这一算法. 用快速数论变换,多项式求逆元和倍增法可以在$O(n log n)$的时间复杂度下求出一个$n$次多项式的开根. 前置技能 快速 ...