2017-05-23 28 views
0

첫 번째 알람에는 작동하지만 다른 알람에는 작동하지 않는 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"); 
       } 
      }]; 
+0

각각의 트리거에 대해 설정하는 '식별자'를 인쇄하여 서로 다른지 확인하십시오. 또한 알림을 테스트하는 방법은 무엇입니까? 수동으로 장치의 시간을 변경하거나 시간을 대기하여? – bhakti123

+0

식별자가 NSLog에서 다릅니다. 심지어 나는 여분의 임의 문자열을 내 식별자에 추가했습니다. 그리고 시뮬레이터의 알람을 확인하고 있습니다. 나는 3 개의 분리 된 경보를 설정했다. 그리고 나는 첫번째 맥박에 가까운 나의 맥북 시간을 정했다. 그것이 작동하면 다시 맥북 시간을 두 번째 알람 근처로 변경하고 프로젝트를 실행합니다. 그러나 그것은 두 번째 또는 다른 경보를 위해 작동하지 않습니다. @ bhakti123 –

+1

모든 알람이 예약되었는지 확인하십시오. 그리고 그들의 다음 방아쇠 날짜는 무엇입니까? 그런 다음 해당 트리거 날짜에 따라 타이밍을 변경하고 작동하는지 확인하십시오. – bhakti123

답변

0

어떻게 트리거 YES 반복 설정에 대한? 또한 이것을 확인하십시오. repeating local notifications

+0

NO !! 반복 (예)은 매일 또는 특정 시간 이후에보고 싶다는 의미입니다. 그러나 여기에서는 별도의 요일에 별도로 알림을 설정하고 있습니다. 나는 3 개의 별도의 시간에 3 일 동안 3 개의 알림을 생성한다고 가정합니다. –

+0

그런 경우 세 가지 식별자를 사용하여 다른 알림을 구분해야합니다. –

+0

예, 내 식별자는 requestWithIdentifier-> [todaySehri description]이며 각 트리거마다 다른 문자열입니다. 그렇다면 어떻게해야합니까? :( –