0

Please Give me Solution i am Wating i have make one Alarm app ,alarm time i have set on local notification fireDate its working properly , and then i try to second time (Snooze time after 1 mint ) i can't able to set local notification , when i try to set second time local notification it's not fire on time otherwise its fire immediately WHERE I DO MISTAKE HERE IS MY CODE

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

second time i am just change the time and call same function Please HELP ME Please share your valuable knowledge

2 Answers2

1

You can't change a UILocalNotification as soon as its scheduled , if you want to change the fireDate you should cancel the notification reschedule it.

Cancel Notificatifcation

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

Relevant question:Delete a particular local notification

Community
  • 1
  • 1
Ezimet
  • 5,058
  • 4
  • 23
  • 29
0

ONE UILocalNotification only fires once.

to have MULTIPLE you need multiple UILocalNotification objects

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135