请用代码解释一下!可能是这个问题的复制品,Manage Multiple UILocal Notification,但还没有得到答案?请将注意力集中在这个问题上,并回答我如何管理超过64的通知?
我有所有UINotification时间的本地数据库,比如下面的问题:
Set multiple UILocalNotification
请回答。
发布于 2015-01-04 16:10:51
无法在任何给定时间安排超过64个本地通知。然而,也许有一些方法可以有效地实现你想要的东西。
UILocalNotification对象上的repeatInterval。此属性获取一个NSCalendarUnit,可用于将重复设置为每小时、每天、每月等。UILocalNotification对象。丢弃所有不再有效的提醒,并在将来尽可能多地排队。UILocalNotification对象,因此当显示通知时,您的用户将不会被带到应用程序。这样,您就可以使用calendar events and reminders为用户设置提醒。您可能希望使用EventKit框架来处理所有繁重的工作。这种方法的优点是,您可以根据需要安排尽可能多的事件。你可以使用日历作为你的通知的后备存储器。因此,每次启动应用程序时,您都会使用其中一个谓词方法(如- (NSArray *)eventsMatchingPredicate:(NSPredicate *)predicate)查询EKEventStore,以查找您创建的事件。发布于 2015-01-02 16:48:54
也许还有其他方法可以管理UILocalNotification。根据每个苹果,你可以设置最多64个通知。因此,要管理超过64个通知,您可以实现以下逻辑。
首先,注册前64个本地通知。在每次应用程序启动或didBecomeActive时,使用[[UIApplication sharedApplication]scheduledLocalNotifications]获取剩余通知或计数。因此,如果您的计数<64,那么就说它是30。因此,添加新的34个通知,现在您的通知总数将为64。每次启动时都要这样做,这样它就可以根据您的需要工作。
也许这会对你有帮助。
发布于 2015-01-08 21:00:40
试试这个,你可以通过选择setDay,setMonth,...来改变间隔。:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:3];
NSDate *date3Days = [calendar dateByAddingComponents:components
toDate:[NSDate date]
options:0];
UIApplication* app = [UIApplication sharedApplication];
NSArray* oldNotifications = [app scheduledLocalNotifications];
if ( oldNotifications ) {
[app cancelAllLocalNotifications];
app.applicationIconBadgeNumber = 0;
}
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];
if (notifyAlarm) {
notifyAlarm.fireDate = date3Days;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.alertBody = NSLocalizedString( @"Push message", @"");
notifyAlarm.soundName = @"sound.wav";
[app scheduleLocalNotification:notifyAlarm];
}如果您想设置一个特定的时间,在该时间之后UILocalNotifications应该出现,您可以创建上述解决方案的一个方法,并循环遍历一个数组,该数组指示您希望显示通知的日期:
NSArray *arrayNumbers = @[@5, @7, @14, @21, @30, @60, @90, @120];
NSDictionary *dictNotifications =
[[NSUserDefaults standardUserDefaults] objectForKey:kUserDefAppStarts];
for ( NSNumber *bla in arrayNumbers ){
NSString *strKey = [NSString stringWithFormat:@"%@%@", kUserDefAppStarts, bla];
NSDictionary *dict = dictNotifications[strKey];
NSString *strMessageQuestion = dict[kKeyMessage];
[self createNotificationWithNumberOfDays:[bla integerValue]
andMessage:strMessageQuestion
userInfo:dict];
}下面是您必须调用的方法
+ (void)createNotificationWithNumberOfDays:(int)days
andMessage:(NSString *)message
userInfo:(NSDictionary *)dict{
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:days];
NSDate *dateAlert = [gregorian dateByAddingComponents:components toDate:[NSDate date] options:0];
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *notifyAlarm = [[UILocalNotification alloc] init];
if( notifyAlarm ){
[notifyAlarm setFireDate:dateAlert];
[notifyAlarm setTimeZone:[NSTimeZone defaultTimeZone]];
[notifyAlarm setSoundName:@"soundname"];
[notifyAlarm setAlertBody:message];
[notifyAlarm setUserInfo:dict];
[app scheduleLocalNotification:notifyAlarm];
}}
https://stackoverflow.com/questions/27737529
复制相似问题