首页 > 解决方案 > swift中的这个Objective C代码是什么?

问题描述

我找到了解决问题的方法,但是代码在 Objective C 中。请有人能快速告诉我这是什么吗?

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

谢谢。

标签: iosobjective-cswiftxcode

解决方案


尝试这个 :

do {
       try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
       try AVAudioSession.sharedInstance().setActive(true)
       UIApplication.shared.beginReceivingRemoteControlEvents()

   }catch{
        print("error")
   }

此外,如果您需要将任何代码从Objective C转换为Swift,您可以使用以下链接进行转换。

https://objectivec2swift.com


推荐阅读