ios - UILocalnotification用于报警应用超过30秒

标签 ios objective-c uilocalnotification repeatingalarm

我正在 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/

相关文章:

ios - UILocalNotification询问用户权限

ios - iphone 5 和 iphone 4 问题上的 iAd 定位

ios - 使用 iOS 图表绘制多条线

ios - 在另一个模态呈现的 viewController 下模糊 viewController?

iOS-Charts 在圆圈下方绘制值

ios - 更新您的应用程序是否会保存用户以前的 Plist 文件?

ios - 本地通知不适用于 iOS 模拟器

ios - 如何获取特定的通知计数

ios - NSInvalidArgumentException : Workout_Tracker. QuickAddViewController collectionView:numberOfItemsInSection:]:无法识别的选择器发送到实例

ios - UITableView 由于可重用单元而混合值