Audio 我将在后台运行计时器多长时间?
在我的应用程序中,我在后台每8秒运行一个计时器来播放自定义声音,它工作正常,但稍后会停止,所以如何在后台连续播放声音? 目前我正在使用下面的代码在后台播放声音Audio 我将在后台运行计时器多长时间?,audio,ios7,timer,Audio,Ios7,Timer,在我的应用程序中,我在后台每8秒运行一个计时器来播放自定义声音,它工作正常,但稍后会停止,所以如何在后台连续播放声音? 目前我正在使用下面的代码在后台播放声音 SystemSoundID soundID; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); AudioServicesPlaySystemSound(soundID); 让我知道在后台连
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
让我知道在后台连续播放声音的好方法。简短回答:你的应用程序只是挂起了
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
回答很长:您缺少背景知识实现的关键部分
您需要告诉iOS您是一个音频应用程序,并且在挂起时请求额外的周期。
UIBackgroundModes有待批准
从:
应用程序的后台模式:
UIBackgroundModes值=音频
该应用程序向用户播放音频内容或在后台录制音频。此内容包括使用AirPlay的流式音频或视频内容
如果你的应用程序不属于以下任何类别,那么你唯一可以将背景时间延长到5秒以上的选项就是调用-beginBackgroundTaskWithName:expirationHandler:。您可能会在30秒内被暂停
音频
地方
网络电话
报摊内容
外部附件
蓝牙中心和蓝牙外围设备
取来
远程通知