gpt4 book ai didi

ios - 当通知超过 64 个限制时如何在 iOS 中安排更多本地通知

转载 作者:可可西里 更新时间:2023-11-01 03:19:49 24 4
gpt4 key购买 nike

<分区>

我正在开发一个日历应用程序,其中包含多个事件(例如 500 个事件),其中包括生日。我正在从 Web 服务下载事件。我想在生日上午 10:00 的特定时间向用户发出每个生日的提醒。我正在使用本地通知来安排提醒,但由于 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", day, 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 个限制后安排更多通知。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com