2012-04-17 32 views
0

我已經爲我的應用程序創建了一個區域設置通知,每天都會觸發,同樣在蘋果開發人員文檔中提到您只能觸發64個通知,所以我的問題是如何防止此限制?我的意思是我的通知計劃每年每天都會發生火災,那麼取消通知然後再按照計劃重新啓動的方法是正確的嗎?取消UILocaleNotification的問題

- (void)cancelLocalNotification:(UILocalNotification *)notification { 

[[UIApplication sharedApplication] cancelLocalNotification:notification; 

} 

這裏是我的通知碼:

- (void) notification { 


    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSPersianCalendar]; 
    NSDate *now = [NSDate date];  
    NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit) fromDate: now]; 

    [componentsForFireDate year]; 
    [componentsForFireDate month]; 
    [componentsForFireDate day]; 
    [componentsForFireDate setHour:1]; 
    [componentsForFireDate setMinute:2]; 
    [componentsForFireDate setSecond:1]; 

    NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate]; 

    UILocalNotification *notification = [[UILocalNotification alloc]init]; 
    notification.fireDate = fireDateOfNotification; 
    notification.timeZone = [NSTimeZone localTimeZone]; 
    notification.repeatInterval= NSDayCalendarUnit; 


    notification.alertAction = @"View"; 
    notification.soundName = UILocalNotificationDefaultSoundName; 

     [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 

} 

回答

0

這裏閱讀您的問題。它肯定解決了你的問題Repeating an iOS local notification

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 
     NSDate *pickerDate = [self.datePicker date]; 
     NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) 
                 fromDate:pickerDate]; 
     NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) 
                 fromDate:pickerDate]; 
     NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
     [dateComps setDay:[dateComponents day]]; 
     [dateComps setMonth:[dateComponents month]]; 
     [dateComps setYear:[dateComponents year]]; 
     [dateComps setHour:[timeComponents hour]]; 
     [dateComps setMinute:[timeComponents minute]]; 
     [dateComps setSecond:[timeComponents second]]; 
     NSDate *itemDate = [calendar dateFromComponents:dateComps]; 

     UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
     if (localNotif == nil) 
      return; 
     localNotif.fireDate = itemDate; 
     localNotif.timeZone = [NSTimeZone defaultTimeZone]; 
     localNotif.alertBody = [eventText text]; 
     localNotif.alertAction = @"View"; 
     localNotif.soundName = audios; 
     localNotif.applicationIconBadgeNumber = 1; 

     [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
     [localNotif release]; 
+0

感謝它只是解釋了限制!我沒有找到任何具體的代碼或東西 – 2012-04-17 06:53:14

+0

示例代碼在那裏。請參閱下面的鏈接,請參閱示例代碼部分。 – akk 2012-04-17 07:01:03

+0

我更新了我的答案 – akk 2012-04-17 07:07:21