我正在 iOS objective-c 中开发 Alarm 基础项目。
当应用程序在后台时,我已经实现了 UILocalnotification
报警。
但我面临的问题是声音只能播放 30 秒。
我怎样才能增加声音的时间间隔,或者有没有其他方法可以代替 UILocalnotification
来实现它。
- (IBAction)Alert:(id)sender{
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd"];
//NSDate *date = [NSDate date];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate =[NSDate dateWithTimeIntervalSinceNow:15];
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = @"Emergency";
localNotif.alertAction = @"View";
localNotif.soundName = @"police.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.repeatInterval = NSYearCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
Note : mp3 file i am using for UILocalnotification is of more that 60min duration.
请指教。 谢谢
最佳答案
如果设备处于事件模式,通知声音只会播放 5 秒。如果设备处于 sleep 模式,通知将播放 30 秒的声音。我想,这是标准行为
根据 Apple 指南,您需要使用时长为 30 秒的 mp3 文件。请检查以下链接。
https://developer.apple.com/reference/usernotifications/unnotificationsound
注意:仅供引用,UILocalNotification 已从 iOS10 中弃用。您需要开始使用 UNUserNotificationCenter。
关于ios - UILocalnotification用于报警应用超过30秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41669733/