2016-11-10 1 views
-1

나는 매일 UILocalNotification을 repeatInterval =로 일정을 잡았지만 특정 알림 (예 : 내일 이후 알림)을 취소하고 싶습니다. 내가 할 수 있을까?반복되는 특정 반복 UILocalNotification을 취소하는 방법?

+0

UIApplication.shard(). scheduledLocalNotifications'에서 예정된 알림을 반복하고 각 알림에서 'fireDate'를 확인하십시오. 'fireDate'가 취소하려는 것과 일치하면 알림을 제거하십시오. – Wes

+0

@Wes "scheduledNotifications"에서 단 하나의 알림입니다. 미래의 알림이 없기 때문에 나는 해고를 비교할 수 없습니다. – Gikas

답변

1

내가이가 반복 매일 통지로 구성된 경우

번호, 당신은 마술 그것에서 하나의 반복을 제거 할 수 있다고 할 수 있습니다. 내일 알림 및 일정 변경을 취소해야합니다.

+0

고맙습니다. UILocalNotification은 내 작업을 위해 충분히 융통성이 없습니다 .. – Gikas

+0

글쎄, 그건 당신이 의미하는 바가 있다면, 마술로 그렇게하지 않을 것입니다. 유연해야하는 것은 귀하의 코드입니다. 예를 들어 매일 알림을 분리했다면 알림을 제거 할 수 있습니다. – matt

0
UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 

    localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:100]; 

    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 

    localNotification.soundName = UILocalNotificationDefaultSoundName; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

이제 추가 한 모든 알림을 나열합니다.

-(void)localNotifcationList{ 
    UIApplication *app = [UIApplication sharedApplication]; 
    NSArray *eventArray = [app scheduledLocalNotifications]; 
    for (int i=0; i<[eventArray count]; i++) 
    { 
     UILocalNotification* yourEventSequence = [eventArray objectAtIndex:i]; 
     NSDictionary *userInfoCurrent = yourEventSequence.userInfo; 
     NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"uid"]]; 
     //Based on your userinfo cancel particular notification. 
// You can also compare fire date here 
} 

이 코드가 작동되기를 바랍니다.

관련 문제