2016-11-10 70 views
-1

我使用repeatInterval =每天计划UILocalNotification,但是我想取消特定的通知,例如后天的通知。我可以那样做吗?如何取消特定的重复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 
} 

我希望这段代码能够正常工作。

相关问题