在警报中,通知在后台正常工作,如下所示:
UILocalNotification *notification1=[[UILocalNotification alloc]init];
notification1.fireDate=alramtime;
notification1.alertBody=@"Training Time";
notification1.repeatInterval=NSDayCalendarUnit;
notification1.soundName=@"Alarm.caf";
///////
previousnotif=[[NSUserDefaults standardUserDefaults]objectForKey:@"notif1"];
previous=[NSKeyedUnarchiver unarchiveObjectWithData:previousnotif];
NSLog(@"alarm %@",previous);
if (previous!= NULL) {
[[UIApplication sharedApplication]cancelLocalNotification:previous];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"notif1"];
}
NSData *alarm1=[NSKeyedArchiver archivedDataWithRootObject:notification1];
[notifdefaults setObject:alarm1 forKey:@"notif1"];
/////////
[[UIApplication sharedApplication] scheduleLocalNotification:notification1];
NSLog(@"new alarm %@",notification1);
但是当我修改它以在前台播放时也如下:..它不工作..只出现警报但没有声音???
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"KNIP"
message:notification.alertBody
delegate:self cancelButtonTitle:@"Close"
otherButtonTitles:nil];
[alert show];
}
@end
当我记录通知的声音文件等属性时......它们工作正常......但没有声音......