Ios 如何在后台连续播放报警声

Ios 如何在后台连续播放报警声,ios,iphone,uilocalnotification,Ios,Iphone,Uilocalnotification,我正在开发一个应用程序,我想发挥一个警报。当我收到本地通知时,警报应立即在后台响起,当我按下按钮时,警报应停止 这是我的密码 NSDate *pickerDate = [self.timePicker date]; NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit

我正在开发一个应用程序,我想发挥一个警报。当我收到本地通知时,警报应立即在后台响起,当我按下按钮时,警报应停止

这是我的密码

NSDate *pickerDate = [self.timePicker date];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
    fromDate:pickerDate];

NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )
    fromDate:pickerDate];

NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setHour:[timeComponents hour]];
NSLog(@"set hour component %ld",(long)[timeComponents hour]); // Notification will fire in one minute

[dateComps setMinute:[timeComponents minute]];
NSLog(@"set setMinute component %ld",(long)[timeComponents minute]);
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object
[localNotification setFireDate:itemDate]; 
//Set the date when the alert will be launched using the date adding the time the user selected on the timer

[localNotification setAlertAction:@"Open"]; //The button's text that launches the application and is shown in the alert
[localNotification setAlertBody:@"Wake up"]; //Set the message in the notification from the textField's text
localNotification.soundName = UILocalNotificationDefaultSoundName;
[localNotification setHasAction: YES]; //Set that pushing the button will launch the application
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
//Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1
[localNotification setUserInfo:[NSDictionary dictionaryWithObject:@"Alarm1" forKey:@"uid"]];
if (isRepeat) {
    localNotification.repeatInterval = NSDayCalendarUnit;
}

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
//Schedule the notification with the system
使用上述代码,声音仅播放30秒。我希望它能连续播放。我找了很多,但找不到


谢谢

这是无法做到的,我这么说的意思是,当应用程序处于后台时,您不能像收到通知时所说的那样在后台播放声音。Apple push和local这两种通知都不支持此功能,您只能为通知添加tink声音,但它不会继续播放

如果要在后台播放声音,则只能在声音开始在前台播放而不是在后台播放时进行,否则只能使用AVAudioPlayer会话播放在后台播放


若你们认为你们可以添加定时器,但定时器在后台也不起作用,那个么你们可以这样做。

这是不可能的,我这么说的意思是,当应用程序在后台时,你们不能像收到通知时所说的那个样在后台播放声音。Apple push和local这两种通知都不支持此功能,您只能为通知添加tink声音,但它不会继续播放

如果要在后台播放声音,则只能在声音开始在前台播放而不是在后台播放时进行,否则只能使用AVAudioPlayer会话播放在后台播放


若你们认为你们可以添加定时器,但定时器在后台也不起作用,那个么你们可以这样做。

这是不可能的,我这么说的意思是,当应用程序在后台时,你们不能像收到通知时所说的那个样在后台播放声音。Apple push和local这两种通知都不支持此功能,您只能为通知添加tink声音,但它不会继续播放

如果要在后台播放声音,则只能在声音开始在前台播放而不是在后台播放时进行,否则只能使用AVAudioPlayer会话播放在后台播放


若你们认为你们可以添加定时器,但定时器在后台也不起作用,那个么你们可以这样做。

这是不可能的,我这么说的意思是,当应用程序在后台时,你们不能像收到通知时所说的那个样在后台播放声音。Apple push和local这两种通知都不支持此功能,您只能为通知添加tink声音,但它不会继续播放

如果要在后台播放声音,则只能在声音开始在前台播放而不是在后台播放时进行,否则只能使用AVAudioPlayer会话播放在后台播放


如果你认为你可以添加定时器,但定时器也不能在后台工作。

使用时间间隔概念你可以使用AVAudioPlayer,因为它可以在后台工作。你能告诉我怎么做吗?比如音频应该在收到通知后立即自动开始播放。使用时间间隔概念你可以使用AVAudioPlayer可以在后台工作。你能告诉我怎么做吗?比如音频应该在收到通知后自动开始播放。时间间隔概念你可以使用AVAudioPlayer,它可以在后台工作。你能告诉我怎么做吗收到通知后立即播放使用时间间隔概念您可以使用AVAudioPlayer,它将在后台工作。您能告诉我如何做到这一点吗?例如,音频应在收到通知后立即自动开始播放