UIBackgroundModes 不起作用 s 广告
我红色了有关 UIBackgroundModes 的 Apple 文档,其中内容如下:
当此键存在时,系统的 音频框架自动阻止 您的申请被暂停 当它移动到背景时。作为 只要它正在播放音频, 应用程序继续运行在 支持该音频的背景。
但是,我有一个使用 AVPlayer 类播放音频流的应用程序,但它不起作用。这个键应该是为了节省我们显式实现音频会话的工作。谁能告诉我为什么这不起作用?有人使用过它并使这项工作有效吗?
I red the Apple documentation about UIBackgroundModes and here is what it says :
When this key is present, the system’s
audio frameworks automatically prevent
your application from being suspended
when it moves to the background. As
long as it is playing audio, the
application continues to run in the
background to support that audio.
However I have an app that plays an audio stream using the AVPlayer class, and it doesn't work with it. This key is suppose to be there to save us the work of implementing an Audio Session explicitely. Can anyone tell me why this is not working then ? Did anyone used it and made this work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在播放音频之前尝试执行以下操作:
Try doing the following before playing your audio:
确保
AVPlayer
的代码确实正在运行。就我而言,即使我启用了Core Location
的密钥,如果我没有通过调用start
在代码中实际使用,应用程序也会被挂起,就好像没有一样键已定义。因此,我通常不会停止
Core Location,而只是让它使用最不准确的选项来保留设备电量,但继续使用后台运行模式。Make sure the code for
AVPlayer
is actually running. In my case, even though I enabled the key forCore Location
, if I don't actually use in the code by callingstart
, the app is suspended, as if no key was defined. For this reason, I usually don'tstop
Core Location but simply let it use the least accurate option to preserve device power, yet continue to use background running mode.