发布网友 发布时间:2022-10-29 18:06
共1个回答
热心网友 时间:2023-10-10 09:11
当程序在不在前台运行时,系统会自动触发你指定的 soundName alertBody
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
UILocalNotification* notification = [[UILocalNotification alloc] init];
<br>
<br>
<br>
<br> notification.timeZone = [NSTimeZone defaultTimeZone];
<br>
<br> notification.soundName = UILocalNotificationDefaultSoundName;
<br>
<br> notification.userInfo = aPlan;
<br>
<br> NSString* alertBody = @"alert message";
<br>
<br> notification.alertBody = alertBody;
<br>
<br> [[UIApplication sharedApplication] scheleLocalNotification:notification];
<br>
<br> [notification release];
2 当程序已经在前台运行时,系统不会触发你指定的soundName alertBody
而是触发AppDelegate中的
?
1
2
3
4
5
6
7
8
9
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
<br>
<br>{
<br>
<br> NSDictionary* dict = [notification userInfo];
<br>
<br> NSLog(@"dict = %@", dict);
<br>
<br>}
其中的dict即为你创建UILocalNotification时候指定的userInfo, 如果需要音效,在此函数中自己实现音效播放即可