我正在尝试UILocalNotification
使用以下逻辑将a设置为每30秒运行一次,但是似乎行为异常。有两个问题:
请有人可以帮助我找出我做错了什么吗?
// 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];
当前无法实现具有间隔的自定义重复。
但是,通知系统最多可以将64个通知排队,因此,您可以做的最接近的事情是手动设置所需数量的通知(每个通知都有不同的徽章编号和不同的fireDate),然后获取通知列表通过设置新的更新来满足您的需求。
这将返回您排队的通知数量:
[[[UIApplication sharedApplication] scheduledLocalNotifications] count]
我也建议您阅读这篇文章以获得更多帮助:
祝好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句