ios - swift中的这个Objective C代码是什么?
问题描述
我找到了解决问题的方法,但是代码在 Objective C 中。请有人能快速告诉我这是什么吗?
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
谢谢。
解决方案
尝试这个 :
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
UIApplication.shared.beginReceivingRemoteControlEvents()
}catch{
print("error")
}
此外,如果您需要将任何代码从Objective C转换为Swift,您可以使用以下链接进行转换。
推荐阅读
- python-3.x - Tensorflow,使用 unique_with_counts 函数时出错
- r - 从r中的数据框中删除unicode字符
- python - 如何在 python 文件中使用二进制数据
- excel - 如何根据文本值在工作表之间复制行
- xmlhttprequest - 从 Google AMP 缓存调用时,使用“action-xhr”提交“AMP 表单”会导致“混合内容”错误,但在它之外可以正常工作
- file - 如何将自定义路径中的 Jenkins 控制台输出保存为文本文件
- c# - 删除 EPPlus 中的 excel 列
- regex - 需要从 Google 表格单元格中列出的段落中提取某些数据
- neo4j - 通过边缘属性过滤度数
- sql - 如何锁定正在执行的存储过程并更改存储过程返回的表?