첫 번째 알람에는 작동하지만 다른 알람에는 작동하지 않는 iOS 10 로컬 알림을 구현했습니다. 나는 델리게이트를 처음으로 델리게이트에서 받았지만, 나중에 실행하지는 않는다.iOS 로컬 알림이 두 번째 발생하지 않지만 getpendingnotificationrequests에 표시됩니다.
내 날짜 메이트는 다음과 같습니다 2017년 5월 28일 14시 4분 7초 0000
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[calendar setTimeZone:[NSTimeZone localTimeZone]];
//(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute)
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now];
NSDate *todaySehri = [calendar dateFromComponents:components];
UNMutableNotificationContent *objNotificationContent = [[UNMutableNotificationContent alloc] init];
objNotificationContent.title = [NSString localizedUserNotificationStringForKey:[NSString stringWithFormat:@"Local.."]] arguments:nil];
objNotificationContent.body = [NSString localizedUserNotificationStringForKey:@"Incoming Local Notification" arguments:nil];
objNotificationContent.sound = [UNNotificationSound soundNamed:[NSString stringWithFormat:@"%@",soundFileBtn.titleLabel.text]]; // [UNNotificationSound defaultSound];//soundFileBtn.titleLabel.text;// [UNNotificationSound defaultSound];
NSDictionary *dict = @{@"alarmID":self.myKey,
@"SOUND_TYPE":[NSString stringWithFormat:@"%li",(long)self.audio_segment.selectedSegmentIndex]
};
NSArray *array = [NSArray arrayWithObjects:dict, nil];
NSDictionary *data = [NSDictionary dictionaryWithObject:array forKey:@"payload"];
[objNotificationContent setUserInfo:data];
//update application icon badge number
objNotificationContent.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 0);
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *compss= [cal components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute)
fromDate:todaySehri];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:compss repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[todaySehri description]
content:objNotificationContent trigger:trigger];
//schedule localNotification
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"Local Notification succeeded");
}
else {
NSLog(@"Local Notification failed");
}
}];
각각의 트리거에 대해 설정하는 '식별자'를 인쇄하여 서로 다른지 확인하십시오. 또한 알림을 테스트하는 방법은 무엇입니까? 수동으로 장치의 시간을 변경하거나 시간을 대기하여? – bhakti123
식별자가 NSLog에서 다릅니다. 심지어 나는 여분의 임의 문자열을 내 식별자에 추가했습니다. 그리고 시뮬레이터의 알람을 확인하고 있습니다. 나는 3 개의 분리 된 경보를 설정했다. 그리고 나는 첫번째 맥박에 가까운 나의 맥북 시간을 정했다. 그것이 작동하면 다시 맥북 시간을 두 번째 알람 근처로 변경하고 프로젝트를 실행합니다. 그러나 그것은 두 번째 또는 다른 경보를 위해 작동하지 않습니다. @ bhakti123 –
모든 알람이 예약되었는지 확인하십시오. 그리고 그들의 다음 방아쇠 날짜는 무엇입니까? 그런 다음 해당 트리거 날짜에 따라 타이밍을 변경하고 작동하는지 확인하십시오. – bhakti123