在我打开应用程序之前,本地通知不会停止发送

时间:2014-09-29 20:29:47

标签: c xcode notifications local appdelegate

在我打开应用程序之前,我的应用程序不会停止发送我在特定时间设置的通知。它会像我每2分钟那样发送给我一点提醒我......

  • (void)applicationDidEnterBackground:(UIApplication *)application {

    NSCalendar * calendar3 = [NSCalendar currentCalendar]; NSDateComponents * components3 = [calendar3 components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)fromDate:[NSDate date]]; [components3 setHour:21]; [components3 setMinute:30]; UIApplication * app3 = [UIApplication sharedApplication]; UILocalNotification * notifyAlarm3 = [[UILocalNotification alloc] init]; if(notifyAlarm3){     notifyAlarm3.fireDate = [calendar3 dateFromComponents:components3];     notifyAlarm3.timeZone = [NSTimeZone defaultTimeZone];     notifyAlarm3.repeatInterval = NSDayCalendarUnit;     notifyAlarm3.soundName = @“not.wav”;     notifyAlarm3.alertBody = @“你好”;     [app3 scheduleLocalNotification:notifyAlarm3]; } }

  • (void)applicationWillEnterForeground:(UIApplication *)application {
    UIApplication * app = [UIApplication sharedApplication]; NSArray * oldNotifications = [app scheduledLocalNotifications]; if([oldNotifications count]> 0){     [app cancelAllLocalNotifications]; } }

期待回应!

0 个答案:

没有答案