1
votes

I have an application in which i have button. When i click on button then generate a local notification. The variable of local notification is set in appDelegate file. For generate local notification i used this code:-

UILocalNotification* ln = [[UILocalNotification alloc] init]; ln.alertBody = @"Time for another cup of coffee!"; ln.applicationIconBadgeNumber = 1; ln.fireDate = notification_date; //[NSDate dateWithTimeIntervalSinceNow:15]; ln.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; NSString *string_date=[formatter stringFromDate:notification_date]; NSDateFormatter* formatter_alarm = [[[NSDateFormatter alloc] init] autorelease]; formatter_alarm.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; [formatter_alarm setDateFormat:@"hh:mm a"]; NSString *str=[formatter_alarm stringFromDate:notification_date]; appDelegate.alarm_time=[NSString stringWithFormat:@"%@",str]; NSLog(@"%@",appDelegate.alarm_time);

        [[NSUserDefaults standardUserDefaults] setObject:appDelegate.alarm_time forKey:@"alarm_on_time"];
        [[NSUserDefaults standardUserDefaults] setObject:string_date forKey:@"alarm_on_date"];
         [[NSUserDefaults standardUserDefaults] synchronize]; 
        NSLog(@"alarm will activate on%@",notification_date);
        ln.soundName = @"alarm.wav";
        AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

        ln.repeatInterval=NSDayCalendarUnit;
        [[UIApplication sharedApplication] scheduleLocalNotification:ln];

// if(appDelegate.appDelegate_notification ==nil) // appDelegate.appDelegate_notification= [[UILocalNotification alloc] init]; appDelegate.appDelegate_notification=ln; [ln release];

Now i have a another button which is used for change the sound of local notification. I wan t that when user click on that button then change the sound of local notification. For that purpose i use this code:-

appDelegate.appDelegate_notification.soundName = @"Blow.wav";

Now problem is that when i click on another button then sound of local notification is not changed. How make that event on button click?

Thanks in advances...

1

1 Answers

1
votes

When we generate any local notification then we can set sound file at that time . If we want to set sound after setting notification then i get only one way that i share here. When we edit any sound of alert then first we have to save fire date of alert and after that we will cancel that alert and set a new alert with same fire date anad this time we will pass new sound file. I use this and working fine.