ios第二次设置为localnofication fireDate时,其工作不正常

ios第二次设置为localnofication fireDate时,其工作不正常,ios,uilocalnotification,Ios,Uilocalnotification,请给我一个我正在等待的解决方案 我制作了一个报警应用程序,我在本地通知fireDate上设置的报警时间工作正常,然后我尝试第二次(1分钟后打盹时间)我无法设置本地通知,当我尝试设置第二次本地通知时,它没有按时点火,否则它会在我出错的地方立即点火 这是我的密码 int getTrackValue=[[defaults valueForKey:@"alarmTrack"] intValue]; NSString *soundName =[appDelegte.globalArrayTrac

请给我一个我正在等待的解决方案 我制作了一个报警应用程序,我在本地通知fireDate上设置的报警时间工作正常,然后我尝试第二次(1分钟后打盹时间)我无法设置本地通知,当我尝试设置第二次本地通知时,它没有按时点火,否则它会在我出错的地方立即点火 这是我的密码

int getTrackValue=[[defaults valueForKey:@"alarmTrack"] intValue];
     NSString *soundName =[appDelegte.globalArrayTrack objectAtIndex:getTrackValue];
    // set up the notifier
    UILocalNotification *localNotification = [[UILocalNotification alloc]init];

    localNotification.fireDate = notiAlarmTime;
    localNotification.timeZone = [NSTimeZone systemTimeZone];
    localNotification.alertBody=@"Please Off Alarm";
    localNotification.alertAction = NSLocalizedString(@"Show", nil);
    localNotification.soundName = [NSString stringWithFormat:@"%@.m4a",soundName];//@"Gentle Rise.m4a";
    localNotification.hasAction = YES;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
第二次我只是改变时间,调用相同的函数 请帮帮我
请分享您的宝贵知识

您不能在计划时间内尽快更改
UILocalNotification
,如果您想更改fireDate,您应该
取消通知并重新计划它

取消通知

 int getTrackValue=[[defaults valueForKey:@"alarmTrack"] intValue];
 NSString *soundName =[appDelegte.globalArrayTrack objectAtIndex:getTrackValue];
// set up the notifier

[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc]init];

localNotification.fireDate = notiAlarmTime;
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.alertBody=@"Please Off Alarm";
localNotification.alertAction = NSLocalizedString(@"Show", nil);
localNotification.soundName = [NSString stringWithFormat:@"%@.m4a",soundName];//@"Gentle Rise.m4a";
localNotification.hasAction = YES;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

相关问题:

ONE
UILocalNotification
只触发一次


要有多个,您需要多个
UILocalNotification
对象

我在设置通知之前使用这一行,但不起作用,我已设置[[UIApplication sharedApplication]cancelAllLocalNotifications];请帮帮我,我不知道我该怎么做。看看我编辑的答案,它应该有效,确保检查你的点火日期是正确的。是的,我的日期是正确的,我使用了这个代码不工作。你一直说不工作,发生了什么事?什么都没有被解雇?试着描述一下你的情况。因为这个代码没有错。