我正在开发类似navi的app .
我必须在预定时间播放声音通知 . 我启用了音频后台模式,但显然我不能使用 NSTimer .
NSTimer
我可以使用什么来在指定时间安排音频通知,因此即使应用程序进入后台也会触发?
你需要探索UILocalNotification,使用它可以在特定的时间间隔设置通知,也可以为你的应用程序设置自定义声音,文件see this example for custom sound .
喜欢
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";
注意:以上代码信用额为this question
您可以使用 UILocalNotification 执行此任务 .
UILocalNotification
2 回答
你需要探索UILocalNotification,使用它可以在特定的时间间隔设置通知,也可以为你的应用程序设置自定义声音,文件see this example for custom sound .
喜欢
注意:以上代码信用额为this question
您可以使用
UILocalNotification
执行此任务 .