iOS 8的多个本地通知

时间:2015-01-13 13:44:05

标签: ios objective-c ios8 xcode6 uilocalnotification

我在不同的交换机中有大约60个本地通知,但是当我尝试并应用多个交换机时,它只运行最后一个。

这是我的代码:

   -(IBAction)theSwitch:(id)sender{

        NSUserDefaults *defaultsB = [NSUserDefaults standardUserDefaults];

   if (switcher.on == 1) {

        NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
        NSDateComponents *dateComponent = [gregCalendar components:NSYearCalendarUnit  | NSWeekCalendarUnit fromDate:[NSDate date]];

        [dateComponent setWeekday:1]; // For sunday
        [dateComponent setHour:16];
        [dateComponent setMinute:30];

        NSDate *fireDate = [gregCalendar dateFromComponents:dateComponent];

        UILocalNotification *notification = [[UILocalNotification alloc]init];
        [notification setAlertBody:textClass1.text];
        [notification setFireDate:fireDate];
        notification.soundName = @"bells.mp3";
        notification.repeatInterval = NSWeekCalendarUnit;
        [notification setTimeZone:[NSTimeZone defaultTimeZone]];
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];


          [defaultsB setObject:@"ON" forKey:@"SwitchState"];
    }
    else  {         UIApplication *app=[UIApplication sharedApplication];
        [app cancelAllLocalNotifications];

          [defaultsB setObject:@"OFF" forKey:@"SwitchStateOFF"];

    }

  } 

0 个答案:

没有答案