到设定的时间让程序退出登录

@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];





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值