本地推送UILocalNotification soundName前台为什么没有声音

2025-05-21 18:13:32
推荐回答(1个)
回答1:

1.当程序在不在前台运行时,系统会自动触发你指定的 soundName alertBody
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
UILocalNotification* notification = [[UILocalNotification alloc] init];







notification.timeZone = [NSTimeZone defaultTimeZone];



notification.soundName = UILocalNotificationDefaultSoundName;



notification.userInfo = aPlan;



NSString* alertBody = @"alert message";



notification.alertBody = alertBody;



[[UIApplication sharedApplication] scheduleLocalNotification:notification];



[notification release];

2 当程序已经在前台运行时,系统不会触发你指定的soundName alertBody

而是触发AppDelegate中的

?
1
2
3
4
5
6
7
8
9
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification



{



NSDictionary* dict = [notification userInfo];



NSLog(@"dict = %@", dict);



}

其中的dict即为你创建UILocalNotification时候指定的userInfo, 如果需要音效,在此函数中自己实现音效播放即可