我有个app需要注销闲置10分钟的用户,即app被最小化或者在后台运行,可以吗?我搜索了很多次,但是如果可能的话,找不到solution.Please来帮我。谢谢。
发布于 2015-04-09 18:16:13
在你的应用委托中,添加存储你的应用程序进入后台的时间的属性。
像@property (nonatomic, strong) NSDate *backgroundedDate;一样
然后在applicationDidEnterBackground:中将日期设置为当前日期:
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.backgroundedDate = [NSDate date];
}然后,当应用程序返回前台时,检查时间差:
- (void)applicationWillEnterForeground:(UIApplication *)application {
if (self.backgroundedDate) {
BOOL isTimedout =[self.backgroundedDate timeIntervalSinceNow] <= -(10 * 60);
if (isTimedout) {
[yourApiClass logou];
}
}
}发布于 2019-08-02 17:19:37
你可以这样做
static dispatch_once_t once;
dispatch_once(&once, ^ {
NSLog(@"Do it once");
self.backgroundedDate = [NSDate date];
});调用applicationWillEnterForeground
- (void)applicationWillEnterForeground:(UIApplication *)application {
if (self.backgroundedDate) {
NSLog(@"Forground %@",[NSDate date]);
BOOL isTimedout = [self.backgroundedDate timeIntervalSinceNow] <= -(5 * 60);
if (isTimedout) {
//Do your work
}
}
}https://stackoverflow.com/questions/29534859
复制相似问题