
我正在开发一个日历应用程序,其中包含多个事件(例如500个事件),其中包括birthdays.I我正在下载事件表单Web服务.我想在生日那天上午10点的特定时间给每个出生日期的用户提醒.我正在使用本地通知来安排警报但我被困住,因为iOS每个应用程序只允许64个通知,我有多个生日.一旦应用程序超过限制,我不知道如何安排更多通知.请建议我如何解决这个问题.下面是我安排通知的代码
- (voID)scheduleNotification:(NSMutableArray *)datesArray withMessage:(NSMutableArray *)messagesArray NotificationID:(Nsstring *)notificationID{ NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateStyle:NSDateFormatterNoStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init]; [formatter1 setDateStyle:NSDateFormatterMediumStyle]; [formatter1 setDateFormat:@"dd/MM/yyyy"]; // NSDate *myTime = [formatter dateFromString:@"06:10 PM"]; NSDate *myTime = [formatter dateFromString:fireTime]; for (int i = 0; i < [datesArray count]; i++) { NSDate *myDate = [formatter1 dateFromString:[datesArray objectAtIndex:i]]; NSDateComponents *dateComponents = [calendar components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:myDate]; NSDateComponents *timeComponents = [calendar components:NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:myTime]; NSDateComponents * newComponents = [[NSDateComponents alloc]init]; NSDateComponents *todayComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]]; int day = [dateComponents day]; int month = [dateComponents month]; [newCompoents setDay:[dateComponents day]]; [newCompoents setMonth:[dateComponents month]]; if (day >= [todayComponents day] && month >= [todayComponents month]) { NSLog(@"day = %d,month = %d",day,month); [newComponents setYear:[todayComponents year]]; } else { NSLog(@"%d,%d",month); [newComponents setYear:[todayComponents year]+1]; } [newComponents setHour:[timeComponents hour]]; [newComponents setMinute:[timeComponents minute]]; NSDate *combDate = [calendar dateFromComponents: newComponents]; localNotif = [[UIlocalnotification alloc] init]; if (localNotif == nil) return; localNotif.fireDate = combDate; localNotif.timeZone = [NSTimeZone defaultTimeZone]; // Notification details Nsstring *message = [@"Wish" stringByAppendingFormat:@" %@%@",[messagesArray objectAtIndex:i],@" On His Birthday"]; localNotif.alertbody = message; // Set the action button localNotif.alertAction = @"VIEw"; localNotif.soundname = UIlocalnotificationDefaultSoundname; localNotif.applicationIconBadgeNumber = 1; // Specify custom data for the notification NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:notificationID]; localNotif.userInfo = infoDict; // Schedule the notification [[UIApplication sharedApplication] schedulelocalnotification:localNotif]; }} 如果我犯了任何错误,请纠正我,并建议一旦超过64限制,如何安排更多通知.
解决方法 我有一个类似的问题和一些可能对你有帮助的选项,尽管它们都有缺陷,这意味着无法保证正确的行为.请记住,重叠的生日可能在这里很有用.如果两个人最终在同一天过生日,请取消并重新安排他们的相关信息.如果你没有通用消息,你可以找到重复发生的其他间隔.
显然,让用户按下通知以打开应用程序会有所帮助(也可能与您的广告收入有关).你可以为你的最后一个尝试一个好消息.
这很麻烦,但你可以使用geofencing(但可能不是远程通知),如下所述:Can push notifications be used to run code without notifying user?.如果添加使用它的功能,您甚至可以获得批准.
我也考虑过传递一个自定义日历,但NSCalendar是免费的CFCalendarRef桥接,故事似乎是我没有运气试图深入研究(并至少获得批准).我很高兴被告知我错了.
总结以上是内存溢出为你收集整理的当通知超过64 时,如何在iOS中安排更多本地通知全部内容,希望文章能够帮你解决当通知超过64 时,如何在iOS中安排更多本地通知所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)