Tôi đang phát triển ứng dụng lịch bao gồm nhiều sự kiện (ví dụ 500 sự kiện) bao gồm sinh nhật.Tôi đang tải xuống các sự kiện tạo dịch vụ web. Tôi muốn cung cấp cho người dùng thông báo về mỗi ngày sinh tại một thời điểm cụ thể vào lúc 10:00 sáng ngày sinh nhật. Tôi đang sử dụng thông báo địa phương để lên lịch cảnh báo nhưng tôi bị kẹt vì iOS chỉ cho phép 64 thông báo cho mỗi ứng dụng và tôi có nhiều sinh nhật. Tôi không biết cách lên lịch thêm thông báo khi ứng dụng vượt quá giới hạn. Xin vui lòng đề nghị làm thế nào tôi sẽ giải quyết vấn đề này. bên dưới là mã của tôi để lên lịch thông báoCách sắp xếp thông báo cục bộ hơn trong iOS khi thông báo vượt quá giới hạn 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 *newCompoents = [[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);
[newCompoents setYear:[todayComponents year]];
}
else{
NSLog(@"%d, %d", day, month);
[newCompoents setYear:[todayComponents year]+1];
}
[newCompoents setHour:[timeComponents hour]];
[newCompoents setMinute:[timeComponents minute]];
NSDate *combDate = [calendar dateFromComponents:newCompoents];
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];
}
}
sửa tôi nếu tôi phạm sai lầm và đề xuất cách lên lịch thông báo khác khi vượt quá giới hạn 64.
IMO bạn có thể lên lịch lại LocalNotification khi bạn mở ứng dụng của mình, như kiểm tra Tổng số địa chỉ đã được lên lịch và nếu nó nhỏ hơn 64, hãy lên lịch lại ở đó .. – Bala
và chỉ xem câu trả lời này http://stackoverflow.com/a/7721445/1059705 – Bala
vâng tôi có thể đếm tổng số thông báo bằng phương pháp đó. ý của bạn là gì khi bạn mở ứng dụng của mình. tôi có cần kiểm tra số lượng trong ủy nhiệm ứng dụng của mình và lên lịch thêm thông báo không. – suhit