在this tutorial之后,我将我的iPad应用设置为在半小时后超时。
这可以通过模拟器上的Xcode或连接到Mac的iPad完美运行。但是,如果我将iPad与Mac断开连接并重新登录我的应用程序,它就不会再超时了。
我希望有人能够阐明为什么会这样。
AppDelegate.m
-(void)applicationDidTimeout:(NSNotification *) notif
{
NSLog (@"time exceeded!!");
UIViewController *controller = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:NULL] instantiateViewControllerWithIdentifier:@"mainView"];
[(UINavigationController *)self.window.rootViewController pushViewController:controller animated:YES];
}
TIMERUIApplication.h
@interface TIMERUIApplication : UIApplication
{
NSTimer *myidleTimer;
}
-(void)resetIdleTimer;
TIMERUIApplication.m
-(void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
if (!myidleTimer)
{
[self resetIdleTimer];
}
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0)
{
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan)
{
[self resetIdleTimer];
}
}
}
-(void)resetIdleTimer
{
if (myidleTimer)
{
[myidleTimer invalidate];
}
int timeout = kApplicationTimeoutInMinutes * 60;
myidleTimer = [NSTimer scheduledTimerWithTimeInterval:timeout target:self selector:@selector(idleTimerExceeded) userInfo:nil repeats:NO];
}
-(void)idleTimerExceeded
{
isLoggedIn = FALSE;
numberOfFIlesAlreadyDownloaded = 0;
numberOfFilesToBeDownloaded = 0;
[[NSNotificationCenter defaultCenter] postNotificationName:kApplicationDidTimeoutNotification object:nil];
}
答案 0 :(得分:0)
一些进一步的试验将这一点缩小到了iPad Auto-Lock。
当iPad进入睡眠状态时,应用也是如此,这意味着计时器被中断。
将iPad连接到Mac禁用自动锁定,这就是为什么我只是在断开连接的iPad上发现它。