Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 每天早上本地通知不起作用?_Ios_Uilocalnotification - Fatal编程技术网

Ios 每天早上本地通知不起作用?

Ios 每天早上本地通知不起作用?,ios,uilocalnotification,Ios,Uilocalnotification,我想每天早上发送一个本地通知,我计划每个applicationidenterbackground:发送一个本地通知,然后在applicationWillEnterForeground:中取消它,如果计划的通知超过0,问题是我不想使用[app cancelalllocalnotifications]因为有更多我不想取消的通知,所以我希望我能解释清楚,无论如何,我的代码如下: 我将本地通知安排在上午9:00: - (void)applicationDidEnterBackground:(UIAppl

我想每天早上发送一个本地通知,我计划每个
applicationidenterbackground:
发送一个本地通知,然后在
applicationWillEnterForeground:
中取消它,如果计划的通知超过0,问题是我不想使用
[app cancelalllocalnotifications]因为有更多我不想取消的通知,所以我希望我能解释清楚,无论如何,我的代码如下:

我将本地通知安排在上午9:00:

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

    user = [self.userdefaults objectForKey:@"user"];
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;
    NSDateComponents *componentsForReferenceDate =
   [calendar components:(NSDayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit ) fromDate:[NSDate date]];

    [componentsForReferenceDate setDay:9] ;
    [componentsForReferenceDate setMonth:11] ;
    [componentsForReferenceDate setYear:2012] ;

    NSDate *referenceDate = [calendar dateFromComponents:componentsForReferenceDate] ;
    NSDateComponents *componentsForFireDate =

    [calendar components:(NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit ) fromDate: referenceDate];

    [componentsForFireDate setHour: 9] ;
    [componentsForFireDate setMinute:0] ;
    [componentsForFireDate setSecond:0] ;

    NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];



    self.diasnot = [[UILocalNotification alloc]init];
    self.diasnot.fireDate = fireDateOfNotification;
    self.diasnot.alertBody = [NSString stringWithFormat: @"Buenos Días %@, tienes %d tareas pendientes. Que tengas buen día!", [self.userdefaults objectForKey:@"user"] ,[[self.userdefaults objectForKey:@"tasks"] count]];

    self.diasnot.timeZone = [NSTimeZone defaultTimeZone];
    if([self.userdefaults objectForKey:@"sound"] == nil)
    {
        self.diasnot.soundName = UILocalNotificationDefaultSoundName;
    }else{
        self.diasnot.soundName = [self.userdefaults objectForKey:@"sound"];
    }


    [application scheduleLocalNotification:self.diasnot];
    [UIApplication sharedApplication].applicationIconBadgeNumber = [[[NSUserDefaults standardUserDefaults] objectForKey:@"tasks"] count];

}
应用程序willenterforeground:
中,我有以下内容:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    UIApplication *app = [UIApplication sharedApplication];

    NSArray *oldNots = [app scheduledLocalNotifications];

    if ([oldNots count] > 0) {
        [app cancelLocalNotification:self.diasnot];
    }


}

问题是,每次我从多任务中删除应用程序时,应用程序都会显示出来,我如何在不删除其他通知的情况下解决这个问题(这些通知安排在其他类别中,而不是在AppDelegate中)谢谢

UILocalNotification
有一个
userInfo
,您可以将其设置为您想要的任何内容。当您想要查找特定的通知时,可以遍历它们并检查
userInfo
的/contents的值

每次我从多任务中删除应用程序时

你的应用程序在这样终止时不会收到回调,所以不要依赖于知道它的发生