0

내 원래 문제 : 19시 3분 19 : 사용자 19:00에 대한 알람을 설정하는 것입니다일정 알림은 다음 주부터 매일 실행하는

, 나는에서 알림을 보여 드리고자합니다 : 09 19:12 통지와 상호 작용하지 않은 경우.

(앱을 오프라인으로 실행할 수 있어야 푸시 알림을 사용하여이 프로세스에 대해 앱을 깨울 방법이 없으며, 로컬 알림을 사용해도 앱이 깨어나지 않습니다.)

사용자가 알림을 예약 할 때마다 4 (1 개의 원본 및 3 개의 반복)를 정확하게 예약하고 사용자가 알림과 상호 작용하면 나머지는 모두 제거합니다.

문제는 알림이 매일 반복됩니다 (1,2,3,4,5,6 또는 7 일). 따라서 모든 알림을 제거하면 다시 표시되지 않습니다.

매일 다음 주부터 알림을 시작하는 방법이 있습니까?

예 :

오늘은 일요일 13시 입니다 그리고 내일 시작 13시 1분에에 일정을 매주 일요일에 대한 통지를하고 싶습니다.

감사합니다.

답변

0

이 코드는 매일 같은 시간에 알림을받는 객관적인 C 코드입니다. 해당 시간에 알림 일정을 설정하십시오. 6 월 8 일 23시에 오전 8시 30 분에 알림을 예약합니다.

-(void)scheduleNotificationAtTime:(NSDate *)date withUserInfo:(NSDictionary *)dictData{ 

     self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];; 
    NSDateComponents *components = [self.gregorian components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:date]; 

    NSDateComponents *components1 = components; 
    components1.hour = components.hour; 
    components1.minute = components.minute; 


    NSInteger hour = [components hour]; 
    NSInteger minute = [components minute]; 

    NSLog(@"Hour %ld Min %ld ", hour,minute); 


    UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components1 repeats:YES]; 

    /* Set notification */ 

    UNMutableNotificationContent *content = [UNMutableNotificationContent new]; 
    content.body = @"Yo received notification."; 
    // content.categoryIdentifier=NSNotificationC; 
    content.sound = [UNNotificationSound defaultSound]; 
    NSString *identifier = @"LocalNotification"; 
    content.userInfo = dictData; 
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier 
                      content:content 
                      trigger:trigger]; 

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
    center.delegate = self; 
    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { 
     if (error != nil) { 
      NSLog(@"Something went wrong: %@",error); 
     } 
    }]; 
}