解决环信实时通话在锁屏后没有声音的问题

  1. iPhone锁屏后 app(集成环信) 语音通话无声音(此时 app 还在运行中)解决办法

最近测试给我报了个 bug,iPhone 手机上跑我的应用时,锁屏后实时语音就没有声音了,解锁后 app 还在运行,通话也还连接着。百度了一阵一直没有类似的答案,坑爹的环信各种 bug。 然后我猜这种情况类似于环信的 demo中 静音的效果,于是找到静音的代码:

 - (void)speakerOutAction
{
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    if (_speakerOutButton.selected) {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    }else {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    }
    [audioSession setActive:YES error:nil];
    
    _speakerOutButton.selected = !_speakerOutButton.selected;
    
}
 

查看了一下 AVAudioSessionCategoryPlayAndRecordAVAudioSessionCategoryPlayback 的文档,发现都有如下几句话

When using this category, your app audio continues with the Silent switch set to silent or when the screen locks. (The switch is called the Ring/Silent switch on iPhone.) To continue playing audio when your app transitions to the background (for example, when the screen locks), add the audio value to the UIBackgroundModes key in your information property list file.

然鹅,并没有卵用!!!

但此时我发现了另外一个东东:

App plays audio or streams audio/video using AirPlay

就在info.plist 文件中加入如下

   <key>UIBackgroundModes</key>
   <array>
       <string>audio</string>
   </array>

App plays audio or streams audio/video using AirPlay 在 plist 的 source 中就是 audio,在 plist 模式下才显示全称

这之后重新编译,就解决了环信实时通话在锁屏后没有声音的问题,我猜测其他应用应该也可以这样解决

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 12,874评论 0 6
  • 突然想写些什么 不知道用怎样的标题 最近发生的事儿好多 每一件似乎都充满了人性 人性的狡诈 自私 贪婪 骨子里的犯...
    慈婧姝阅读 1,720评论 0 0
  • 活法是上游,结果是下游; 上游不改,下游不变。 ~紫雨老师 听了老师的换活课程后,...
    王福才_中换阅读 1,706评论 0 3
  • 19岁那年,入学聚会上我遇见了那个待人如春风般的女孩。从来不懂情为何物的我突然开了窍,喜欢上了那个总喜欢咧嘴傻...
    无诗无酒何得乐阅读 4,172评论 0 0

友情链接更多精彩内容