2017-01-16 56 views
0

我正在iOS目标c中的报警基础项目上工作。 我在应用程序的后台执行了UILocalnotification报警。 但我面临的问题是声音只能播放30秒。超过30秒的报警应用程序的UILocalnotification

我该如何增加声音的时间间隔或是否有其他方法来实现它,而不是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. 

请指教。 谢谢

+1

您需要将该文件分成多个30s声音文件,并发出多个通知 – Tj3n

+0

@ Tj3n感谢您的回复。但我的mp3文件更多是30秒。 –

回答

1

如果设备处于活动模式,通知声音仅播放5秒钟。如果设备处于睡眠模式,通知将播放30秒的声音。我想,这是标准的行为

根据苹果的指导方针,你需要使用持续30秒的MP3文件。请检查下面的链接。

https://developer.apple.com/reference/usernotifications/unnotificationsound

注:仅供参考,UILocalNotification从iOS10弃用。您需要开始使用UNUserNotificationCenter。

+0

除了通知之外,还有其他方法可以实现闹钟功能吗?因为通知只能播放5或30秒。而预期的结果是它应该发挥更多的60秒? –

+0

这是不可能的,除非你设置两个本地通知。 iOS的闹钟应用程序有超过30秒的播放声音的特权。请检查链接哪些可能有用for.you.http://stackoverflow.com/questions/9445090/alarm-clock-app-in-ios – miOS