Ios 前台本地通知
在报警中,通知在后台工作正常,如下所示:Ios 前台本地通知,ios,objective-c,notifications,local,Ios,Objective C,Notifications,Local,在报警中,通知在后台工作正常,如下所示: UILocalNotification *notification1=[[UILocalNotification alloc]init]; notification1.fireDate=alramtime; notification1.alertBody=@"Training Time"; notification1.repeatInterval=NSDayCalendarUnit; notification1.
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
当我记录通知的声音文件等属性时……它们工作正常……但没有声音……在前台,如果需要,您必须提供警报视图并播放声音,通知将只调用ApplicationIDReceiveLocalNotification。您可以使用
AVAudioPlayer
//Playing sound
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath],notification.soundName]];
AVAudioPlayer *newAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
self.audioPlayer = newAudioPlayer;
self.audioPlayer.numberOfLoops = -1;
[self.audioPlayer play];
[newAudioPlayer release];
当系统交付时,应用程序是否最重要且可见
通知,没有显示警报,没有图标标记,也没有声音
正在播放。但是,应用程序:didReceiveLocalNotification:是
如果应用程序委托实现它,则调用。这个
UILocalNotification实例被传递到此方法中
委托可以检查其属性或从中访问任何自定义数据
用户信息字典