2016-05-26 28 views
0
  1. 我想在開始日期到結束日期之間停止本地通知。
  2. 下面是一段代碼,這是我的日常本地通知寫着:如何在ios中的開始日期和結束日期之間禁用本地通知

    UILocalNotification *localNotif11 = [[UILocalNotification alloc] init]; 
    localNotif11.alertBody = @"Hello"; 
    [email protected]"Reminder"; 
    [email protected]"notification.caf"; 
    NSDateComponents *components11 = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:[NSDate date]]; 
    [components11 setHour:11]; 
    [components11 setMinute:00]; 
    localNotif11.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components11]; 
    localNotif11.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; 
    
    NSLog(@"%@",localNotif11.fireDate); 
    [localNotif11 setRepeatInterval:NSCalendarUnitDay]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif11]; 
    
+0

你不能暫停/停止'UILocalNotification'。因此您應該取消並創建新計劃'UILocalNotification' –

+0

您可以在本地通知的用戶信息中爲密鑰設置唯一值。然後獲取所有本地通知,循環訪問數組並刪除特定的通知。 –

+0

可以請您分享示例code.if用戶想要去度假,他會選擇開始日期和結束日期。在這個日期之間,我們不想發送通知 – gaurav

回答

1

試試這個代碼:

UILocalNotification *notification = [[UILocalNotification alloc] init]; 
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7]; 
notification.alertBody = @"This is local notification!"; 
notification.timeZone = [NSTimeZone defaultTimeZone]; 
notification.soundName = UILocalNotificationDefaultSoundName; 
notification.applicationIconBadgeNumber = 10; 

[[UIApplication sharedApplication] scheduleLocalNotification:notification]; 

UILocalNotification *notification1 = [[UILocalNotification alloc] init]; 
notification1.fireDate = [NSDate dateWithTimeIntervalSinceNow:8]; 
notification1.alertBody = @"This is local notification!"; 
notification1.timeZone = [NSTimeZone defaultTimeZone]; 
notification1.soundName = UILocalNotificationDefaultSoundName; 
notification1.applicationIconBadgeNumber = 10; 

[[UIApplication sharedApplication] scheduleLocalNotification:notification1]; 

NSArray *arr = [[UIApplication sharedApplication] scheduledLocalNotifications]; 

for (UILocalNotification *notif in arr) { 
    NSLog(@"Local:: %@",notif.fireDate); 
} 

你在目前你直到日期檢查firedate。

+0

我不想刪除通知我只是想停止通知時用戶選擇假期的開始日期和結束日期。 – gaurav

+0

但我想在某日期之後停止通知 – gaurav

+0

您被檢查的火鳥包括開始日期和結束日期。包括寫代碼: [[UIApplication sharedApplication] cancelLocalNotification:notification]; –

相關問題