내 앱이 이후 UNNotificationRequest 일정을 예약합니다. 각 요청에는 고유 식별자가 있습니다. repeat가 NO로 설정되어 있기 때문에 UNCalanderNotificationTrigger에서 반복되는 경우가 아닙니다. 오히려 각 요청은 다른 미래 달력 날짜로 설정되지만 모두 연속적으로 그리고 본질적으로 동시에 요청됩니다. 각 트리거는 다음 메소드로 전달되는 간격 (NSTimeInterval)에 의해 설정됩니다. 응용 프로그램이 백그라운드 나 포 그라운드에있을 때 UNNotificationCenter 대리인 (appDelegate)에서 요청을받지 못합니다. Apple의 개발자 설명서에는 관련 사례가 없습니다. 완성 처리기에서 완성을 검사해야하는지 궁금합니다. (코드에는 withCompletionHandler : nil이 있지만, Apple의 예제에 나와 있습니다.)두 가지 이상의 UNNotificationRequest가있을 수 있습니까?
0
A
답변
0
대답은 "예"이며 여러 개의 미해결 NSNotificationRequest가있을 수 있습니다. 다음 코드가 작동합니다.
-(UNNotificationRequest *)triggerNotifications: (NSString *)identifier : (NSTimeInterval) interval{
// Note: identifier must be unique or else each new request causes all others to be cancelled.
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = NSLocalizedString(@"Timer expired", nil);
content.body = NSLocalizedString(@"Touch to continue", nil);
NSUserDefaults *storage = [NSUserDefaults standardUserDefaults];
BOOL sound = [storage boolForKey:@"sound permission granted"];
if(sound){
if([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeyDoorBell, nil)]){
content.sound = [UNNotificationSound soundNamed:@"doorbell.caf"];
}else if ([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeySystemDefault, nil)]){
content.sound = [UNNotificationSound defaultSound];
}else if ([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeyElectronicChime, nil)]){
content.sound = [UNNotificationSound soundNamed:@"electronic_chime.caf"];
}else{
if([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeyComputer, nil)]){
content.sound = [UNNotificationSound soundNamed:@"Computer.caf"];
}
}
}
content.categoryIdentifier = @"com.nelsoncapes.localNotification";
NSDate *today = [NSDate date];
NSDate *fireDate = [today dateByAddingTimeInterval:interval];
// first extract the various components of the date
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger year = [calendar component:NSCalendarUnitYear fromDate:fireDate];
NSInteger month = [calendar component:NSCalendarUnitMonth fromDate:fireDate];
NSInteger day = [calendar component:NSCalendarUnitDay fromDate:fireDate];
NSInteger hour = [calendar component:NSCalendarUnitHour fromDate:fireDate];
NSInteger minute = [calendar component:NSCalendarUnitMinute fromDate:fireDate];
NSDateComponents *components = [[NSDateComponents alloc]init];
components.year = year;
components.month = month;
components.day = day;
components.hour = hour;
components.minute = minute;
// construct a calendarnotification trigger and add it to the system
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier: identifier content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:^(NSError *error){
if(error){
NSLog(@"error on trigger notification %@", error);
}
}];
return request;
}
관련 문제
- 1. Symfony에서 두 가지 이상의 유효성 검사기를 정의 할 수 있습니까?
- 2. ListView에 Android에서 두 가지 이상의 행 레이아웃 유형이있을 수 있습니까?
- 3. Magento webshopapps Matrixrate - 두 가지 이상의 배송 방법이 있습니까?
- 4. Hubot에 두 가지 이상의 인수를 전달하는 방법
- 5. 두 개 이상의 조건을 확인할 수 있습니까?
- 6. 두 가지 공통점이 있습니까?
- 7. Django는 두 가지 버전을 실행할 수 있습니까?
- 8. 두 가지 활동을 동시에 실행할 수 있습니까?
- 9. 하나의 작업에는 두 가지 방법이있을 수 있습니까?
- 10. 두 가지 디버거 인스턴스를 실행할 수 있습니까?
- 11. DynamoDB의 두 가지 속성을 비교할 수 있습니까?
- 12. 두 가지 버전의 Maven 빌드를 유지할 수 있습니까?
- 13. Imageview에 두 개 이상의 Onclick 메서드를 연결할 수 있습니까?
- 14. Maude 시스템에서 연산이 두 개 이상의 피연산자를 가질 수 있습니까?
- 15. 셀러리 작업자가 한 번에 두 가지 이상의 작업을 수행 할 수 있습니까? 다음과 같은
- 16. 우리는 UFT에서 두 가지 이상의 작업에 대해 단일 엑셀 개체를 사용할 수 있습니까?
- 17. ruby on rails 스크립트에 두 가지 이상의 오류가있는 경우 표시되는 스크립트가 무엇인지 어떻게 알 수 있습니까?
- 18. 두 가지 주요 구성 요소를 병합 할 수 있습니까?
- 19. 두 가지 구현간에 차이점이 있습니까?
- 20. 왜 두 가지 결과가 있습니까?
- 21. Smarty의 두 가지 경로가 있습니까?
- 22. 두 개 이상의 WebMatrix 사이트를 동시에 실행할 수 있습니까?
- 23. 내가이 두 가지 조건이 두 가지 조건
- 24. Ember.js에서 두 가지 이상의 유형의 레코드를 모두 찾는 방법은 무엇입니까?
- 25. ActiveAdmin을 사용하여 두 가지 이상의 관리자 유형 로그인 처리
- 26. Haskell의 'reads'가 두 가지 이상의 목록 항목을 반환하는 시나리오는 무엇입니까?
- 27. Django Rest Framework에서 두 가지 이상의 권한을 허용하지 않습니다.
- 28. 3 가지 이상의 값으로 검색
- 29. 동일한 열에 두 가지 이상의 코드 유형에 대한 SQL 문
- 30. 웹 응용 프로그램을 만들고 싶다면 두 가지 이상의 언어를 알아야합니까?