2014-02-19 70 views
0

我有一個奇怪的情況,在一個按鈕單擊事件我添加計時器到NSRunLoop應該在'x'分鐘後觸發。但是,如果iPad在'x'分鐘之前進入睡眠狀態,並且計時器值已達到其「x」值,並且之後再次打開我的應用程序,則不會顯示警報。當iPad處於睡眠模式時,用於顯示UIAlertView的NSRunLoop

因此,如果計時器時間到了,iPad處於睡眠模式,它應該會在我重新啓動應用程序後顯示警報。以下是我的代碼。

NSTimer *uiTimer = [NSTimer timerWithTimeInterval:[x intValue] * 60 target:self selector:@selector(fireTheMethod:) userInfo:nil repeats:NO]; 
[[NSRunLoop mainRunLoop] addTimer:uiTimer forMode:NSRunLoopCommonModes]; 

-(void) fireTheMethod 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil]; 
    [alert show]; 
} 
+0

我認爲你應該去本地通知,而不是顯示警報。 – Pawan

回答

0

也許你可以改變你的邏輯一點點?在您的應用applicationDidEnterBackground:中,您可能會使您的計時器無效,並保存當前時間。然後在applicationWillEnterForeground:中,可以獲取當前時間,如果時間差大於所需的時間間隔,則顯示警報。

相關問題