到设定的时间让程序退出登录
2016-03-16 18:08
477 查看
@interface MBWindow :
UIWindow
@end
@implementation MBWindow
- (void)dealloc{
[[NSNotificationCenter
defaultCenter] removeObserver:self];
}
- (id)initWithFrame:(CGRect)frame{
self = [super
initWithFrame:frame];
if (self) {
}
return
self;
}
/**
* 程序超时控制。在"退出时间设定"(服务设定/退出时间设定)设置后,用户登录后,超过该时间屏幕没有响应,强行退出登录。
*/
- (void)sendEvent:(UIEvent *)event{
[super
sendEvent:event];
NSInteger timeoutInterval = [[NSUserDefaults
standardUserDefaults] integerForKey:@"time"];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(appTimeout) object:nil];
if ([USER_DEFAULT
boolForKey:kIsLogin]&&timeoutInterval) {
[self performSelector:@selector(appTimeout) withObject:nil afterDelay:timeoutInterval * 60];
}
}
- (void)userLogout{
[NSObject
cancelPreviousPerformRequestsWithTarget:self
selector:@selector(appTimeout)
object:nil];
}
- (void)appTimeout{
NSInteger timeInterval = [[NSUserDefaults
standardUserDefaults] integerForKey:@"time"];
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:nil
message:[NSString
stringWithFormat:@"程序%ld分钟没操作,请重先登录",(long)timeInterval]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"确定",
nil];
[alert show];
//到这里其实就是强制让其 退出登录 系统的时间到了之后
[USER_DEFAULT
setBool:NO
forKey:kIsLogin];
// [USER_DEFAULT setBool:NO forKey:kAutoLogin];
[[NSNotificationCenter
defaultCenter] postNotificationName:kNotificationLoginSuccess
object:nil];
});
}
self.window = [[MBWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
获取登录 的状态
//判断是否登录
BOOL isLogin = [USER_DEFAULT
boolForKey:kIsLogin];
BOOL autoLogin = [USER_DEFAULT
boolForKey:kAutoLogin];
if (isLogin && autoLogin) {
_isLogin =
YES;
}else{
_isLogin =
NO;
}
登录成功把信息和时间存在本地
[[NSUserDefaults
standardUserDefaults] setInteger:1000
forKey:@"time"];
[[NSUserDefaults
standardUserDefaults] synchronize];
UIWindow
@end
@implementation MBWindow
- (void)dealloc{
[[NSNotificationCenter
defaultCenter] removeObserver:self];
}
- (id)initWithFrame:(CGRect)frame{
self = [super
initWithFrame:frame];
if (self) {
}
return
self;
}
/**
* 程序超时控制。在"退出时间设定"(服务设定/退出时间设定)设置后,用户登录后,超过该时间屏幕没有响应,强行退出登录。
*/
- (void)sendEvent:(UIEvent *)event{
[super
sendEvent:event];
NSInteger timeoutInterval = [[NSUserDefaults
standardUserDefaults] integerForKey:@"time"];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(appTimeout) object:nil];
if ([USER_DEFAULT
boolForKey:kIsLogin]&&timeoutInterval) {
[self performSelector:@selector(appTimeout) withObject:nil afterDelay:timeoutInterval * 60];
}
}
- (void)userLogout{
[NSObject
cancelPreviousPerformRequestsWithTarget:self
selector:@selector(appTimeout)
object:nil];
}
- (void)appTimeout{
NSInteger timeInterval = [[NSUserDefaults
standardUserDefaults] integerForKey:@"time"];
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:nil
message:[NSString
stringWithFormat:@"程序%ld分钟没操作,请重先登录",(long)timeInterval]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"确定",
nil];
[alert show];
//到这里其实就是强制让其 退出登录 系统的时间到了之后
[USER_DEFAULT
setBool:NO
forKey:kIsLogin];
// [USER_DEFAULT setBool:NO forKey:kAutoLogin];
[[NSNotificationCenter
defaultCenter] postNotificationName:kNotificationLoginSuccess
object:nil];
});
}
self.window = [[MBWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
获取登录 的状态
//判断是否登录
BOOL isLogin = [USER_DEFAULT
boolForKey:kIsLogin];
BOOL autoLogin = [USER_DEFAULT
boolForKey:kAutoLogin];
if (isLogin && autoLogin) {
_isLogin =
YES;
}else{
_isLogin =
NO;
}
登录成功把信息和时间存在本地
[[NSUserDefaults
standardUserDefaults] setInteger:1000
forKey:@"time"];
[[NSUserDefaults
standardUserDefaults] synchronize];
相关文章推荐
- Linux-文件系统管理
- ifconfig命令--查看、配置、启用或禁用网络接口的工具
- rest service技术选型
- CentOS 7 安装 Gitlab
- 中缀表达式转后缀表达式的方法
- 每周算法讲堂 floyd
- paper 43 :ENDNOTE下载及使用方法简介
- 跨程序共享数据
- QT 窗体之间(MainWindow 和 Dialog)数据传递
- Spring配置c3p0数据源时出错报:java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector
- Mysql主主同步配置方法
- Percona Toolkit工具箱的安装与使用--完成复杂的mysql操作。
- HTML单选、多选、按钮、下拉框、文本输入框
- Java 四舍五入计算问题
- Android自定义控件之onMeasure
- strlen 和 mb_strlen 与 substr 和 mb_substr 的区别
- 饿了么移动APP的架构演进
- 生成10位随机字符串
- 浏览器滚动条触底时出发事件
- Bzoj 2818: Gcd 莫比乌斯,分块,欧拉函数,线性筛