2016-11-10 68 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 
} 

我希望這段代碼能夠正常工作。

相關問題