iPhone:在iOS 10静音模式下播放声音

时间:2017-01-08 19:43:00

标签: ios iphone react-native avaudioplayer

我已经阅读了很多帖子和文章,而且当iPhone处于静音状态时,我没有运气播放音频。我使用react-native-sound使用了AVAudioPlayer。以下呼叫在没有任何运气的情况下成功,声音在沉默时传来。

  NSError *setCategoryError = nil;
  BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
  if (!success) { /* handle the error condition */ }

  NSError *activationError = nil;
  success = [audioSession setActive:YES error:&activationError];
  if (!success) { /* handle the error condition */ }

有什么建议吗?

资源: https://developer.apple.com/library/content/qa/qa1668/_index.html

1 个答案:

答案 0 :(得分:-1)

我也在努力解决这个问题。我不认为这是完全可能的。我可以在应用程序处于前台时以静音模式播放声音,然后在后台继续播放,但我认为iOS不允许您在应用处于后台并以静音模式触发声音。我正在使用本地通知触发声音播放。

有些人在info.plist中将运行设置'应用程序无法在后台运行'设置为YES,当有人将应用程序锁定在应用程序仍在前台但我需要该应用程序工作时才将应用程序保留在前台如果应用程序在后台时手机已锁定。

目前我所知道的唯一解决方案是播放无声音轨然后告诉它在播放后保持活动状态(不浪费cpu /电池)。请参见链接here。 Apple通常不会在应用评论中批准这一点。或者使用位置更新。

相关问题