2011-11-07 72 views
0

我有一个应用程序,我有按钮。当我点击按钮,然后生成本地通知。本地通知的变量在appDelegate文件中设置。为了生成本地通知,我使用了以下代码: -如何更改本地通知的声音名称?

UILocalNotification * ln = [[UILocalNotification alloc] init]; ln.alertBody = @“又来一杯咖啡的时间!”; 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]; 

//如果(appDelegate.appDelegate_notification ==无) // appDelegate.appDelegate_notification = [[UILocalNotification的alloc] INIT]; appDelegate.appDelegate_notification = ln; [发布];

现在我有另一个按钮,用于改变本地通知的声音。我不想当用户点击那个按钮,然后改变本地通知的声音。为此,我使用此代码: -

appDelegate.appDelegate_notification.soundName = @“Blow.wav”;

现在的问题是,当我点击另一个按钮,然后本地通知的声音没有改变。如何使按钮点击该事件?

感谢在进步......

回答

0

当我们产生任何本地通知那么我们就可以在那个时候设置声音文件。如果我们想在设置通知后设置声音,那么我只能在这里分享一种方式。当我们编辑任何警报声音时,首先我们必须保存警报的火警日期,之后我们将取消该警报,并设置一个具有相同火灾日期的新警报,此时我们将传递新的声音文件。我用这个,工作正常。