ios第二次设置为localnofication fireDate它无法正常工作

时间:2014-08-21 14:22:20

标签: ios uilocalnotification

请给我解决方案我很好 我已经制作了一个闹钟应用程序,闹钟时间我设置了本地通知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];

第二次我只是改变时间并调用相同的功能 请帮我 请分享您的宝贵知识

2 个答案:

答案 0 :(得分:1)

如果您想要更改fireDate UILocalNotification,则无法在计划后立即更改cancel the notification reschedule it

取消通知

 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];

相关问题:Delete a particular local notification

答案 1 :(得分:0)

ONE UILocalNotification只会触发一次。

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