3
我使用了本地通知並安排了啓動日期,但是當應用程序處於後臺並且我打開通知托盤查看通知時,本地通知會自動觸發,但是火災日期是剩餘的..有任何解決方案來解決這個問題UILocalNotification當我打開通知托盤查看通知時觸發
我使用了本地通知並安排了啓動日期,但是當應用程序處於後臺並且我打開通知托盤查看通知時,本地通知會自動觸發,但是火災日期是剩餘的..有任何解決方案來解決這個問題UILocalNotification當我打開通知托盤查看通知時觸發
這聽起來像你有兩個問題。首先,本地通知是在過去設置了一個啓動日期的情況下創建的 - 這就是爲什麼一旦您打開應用程序就會顯示它。
其次,您可能會將通知的repeatInterval設置爲非零值,這會導致它不止一次出現。
請參見下面的代碼來設置一個本地通知火在下午3點:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"This is a test alert";
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setHour: 15];
[comps setMinute: 0];
[comps setSecond: 0];
NSDate *threePM = [currentCalendar dateFromComponents:comps];
// Test if the current time is after three or not:
if(threePM != [threePM earlierDate: [NSDate date]])
{
comps = [[NSDateComponents alloc] init];
[comps setDay: 1];
threePM = [currentCalendar dateByAddingComponents: comps toDate: threePM options: 0];
}
localNotification.fireDate = threePM;
localNotification.repeatInterval = 0;
[[UIApplication sharedApplication] scheduleLocalNotification: localNotification];