我試圖建立一個UILocalNotification
使用下面的邏輯,每30秒運行,但它似乎是行爲不端。有兩個問題:UILocalNotification每30秒
- 當通知被解僱時,似乎有很多人都是一次性的,而不是每30秒一次。
- 應用程序圖標徽章編號似乎並未增加。它只是停留在1.
請有人能幫我弄清楚我做錯了什麼嗎?
// Create 'base' notification we can use
UILocalNotification *baseNotification = [[UILocalNotification alloc] init];
baseNotification.timeZone = [NSTimeZone defaultTimeZone];
baseNotification.repeatInterval = NSMinuteCalendarUnit;
baseNotification.alertBody = @"My Message.";
baseNotification.alertAction = @"My Alert Action";
baseNotification.soundName = UILocalNotificationDefaultSoundName;
UILocalNotification *alertOne = [baseNotification copy];
alertOne.applicationIconBadgeNumber++;
alertOne.fireDate = [[NSDate date] dateByAddingTimeInterval:30];
[[UIApplication sharedApplication] scheduleLocalNotification:alertOne];
UILocalNotification *alertTwo = [baseNotification copy];
alertTwo.applicationIconBadgeNumber++;
alertTwo.fireDate = [[NSDate date] dateByAddingTimeInterval:60];
[[UIApplication sharedApplication] scheduleLocalNotification:alertTwo];
你是什麼意思的「當通知被解僱」?你是否一次看到很多通知提醒,或者'application:didReceiveLocalNotification:'方法被多次調用? – Hejazi
我的意思是我一次看到很多通知警報。 –
你是否通過調用'cancelAllLocalNotifications'來取消所有先前的預定警報? – Hejazi