【发布时间】:2013-10-13 19:40:56
【问题描述】:
我正在尝试使用以下逻辑将UILocalNotification 设置为每 30 秒运行一次,但它似乎行为不端。有两个问题:
- 当通知被触发时,似乎同时有很多通知,而不是每 30 秒 1 个。
- 应用程序图标徽章数量似乎没有增加。它只是保持在 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:被多次调用? -
我的意思是我同时看到许多通知警报。
-
您是否通过致电
cancelAllLocalNotifications取消所有之前的预定提醒?
标签: iphone ios objective-c ios7 uilocalnotification