我有一个iOS 7应用程序,将用于自助服务终端设置。如果没有人使用它一段时间(1-2分钟),我想让应用程序回到开头。知道我怎么能这样做吗?似乎必须有一些方法可以做到这一点,因为屏幕将在未使用一段时间后锁定。
答案 0 :(得分:4)
每次互动后设置NSTimer
,在互动发生时使其无效。当计时器到期时执行重置。
答案 1 :(得分:0)
答案 2 :(得分:0)
首先,您需要验证您的main.m文件以使用您的委托文件:
int retVal = UIApplicationMain(argc, argv, @"AppDelegate", @"AppDelegate");
您可以覆盖实现文件中的send事件方法
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
// Only want to reset the timer on a Began touch or an Ended touch, to reduce the number of timer resets.
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0) {
// allTouches count only ever seems to be 1, so anyObject works here.
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded)
[self resetIdleTimer];
}
}
- (void)resetIdleTimer {
if (idleTimer) {
[idleTimer invalidate];
[idleTimer release];
}
idleTimer = [[NSTimer scheduledTimerWithTimeInterval:maxIdleTime target:self selector:@selector(idleTimerExceeded) userInfo:nil repeats:NO] retain];
}
- (void)idleTimerExceeded
{
NSLog(@"expected time exceeded");
}