gpt4 book ai didi

ios - 在后台运行应用程序时安排音频通知

转载 作者:行者123 更新时间:2023-12-01 17:19:18 24 4
gpt4 key购买 nike

我正在开发类似navi的应用程序。

我必须在预定时间播放声音通知。我已经启用了音频背景模式,但是显然我不能为此使用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

关于ios - 在后台运行应用程序时安排音频通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20899317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com