有时本地通知会为单个事件编号生成多个通知。但是我没有进行测试,这是一种罕见的情况。
特定操作系统版本是否有任何问题? 代码在这里
-(void)startLocalNotification:(NSDate *)notificationDate startTimeOfShift:(NSString *)startTime {
NSLog(@"startLocalNotification");
NSDateFormatter *newDateFormatter =[[NSDateFormatter alloc]init];
[newDateFormatter setDateFormat:@"dd/MM/yyyy"];
NSString *startDateStr =[newDateFormatter stringFromDate:notificationDate];
NSString *scheduleDateTimeString =[NSString stringWithFormat:@"%@ %@:00.000",startDateStr,startTime];
NSLog(@"scheduleDateTimeString :%@",scheduleDateTimeString);
NSDate *setFireDate,*notificationScheduledDateAndTime,*currentDate;
[newDateFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss.SSS"];
notificationScheduledDateAndTime =[newDateFormatter dateFromString:scheduleDateTimeString];
setFireDate =[notificationScheduledDateAndTime dateByAddingTimeInterval:-60*15];
currentDate =[NSDate date];
// NSTimeInterval distanceBetweenDates = [notificationScheduledDateAndTime timeIntervalSinceDate:[NSDate date]];
// NSLog(@"distanceBetweenDates :%f",distanceBetweenDates);
NSLog(@"Current Date :%@ setFireDate :%@",currentDate,setFireDate);
if(counts > 15){
doNotShowNotificationAlert = NO;
}
switch ([currentDate compare:setFireDate]){
case NSOrderedAscending: {
NSLog(@"NSOrderedAscending");
}
case NSOrderedSame: {
NSLog(@"NSOrderedSame");
if(doNotShowNotificationAlert == NO){
notification = [[UILocalNotification alloc] init];
notification.fireDate = setFireDate;
NSLog(@"setFireDate :%@",setFireDate);
notification.alertBody = @"Shift Start Alert!! 15 mins to go.";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"100" forKey:@"notificationID"];
notification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
NSLog(@"info Dict :%@",infoDict);
doNotShowNotificationAlert = YES;
}
break;
}
case NSOrderedDescending: {
NSLog(@"NSOrderedDescending");
break;
}
}
}