我正在开发类似navi的app.
我必须在预定时间播放声音通知.我启用了音频后台模式,但显然我无法使用NSTimer它.
我可以使用什么来在指定时间安排音频通知,因此即使应用程序进入后台也会触发?
您需要探索UILocalNotification,您可以使用该UILocalNotification以特定间隔设置通知,并且还可以设置自定义声音,请参阅此示例以获取应用的自定义声音文件.
喜欢
UILocalNotification *notif = [[UILocalNotification alloc] init];
NSDateComponents *dateComp = [[NSDateComponents alloc] init];
[dateComp setDay:YourDay];
[dateComp setHour:YourHour];
[dateComp setMinute:YourMinute];
NSLog(@"Year: %i, Month: %i, Day: %i, Time:%i:%i\n",[dateComp year], [dateComp month],
[dateComp day], [dateComp hour], [dateComp minute]);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
notif.fireDate = [gregorian dateFromComponents:dateComp];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = YourAlertBody;
notif.soundName = @"fireburn.caf";
Run Code Online (Sandbox Code Playgroud)
注意:上面的代码信用就是这个问题
| 归档时间: |
|
| 查看次数: |
81 次 |
| 最近记录: |