1、在AppDelegate里,
首先要import AVFoundation
,
然后在func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool `方法里添加如下代码:
let session = AVAudioSession.sharedInstance()
do {
try session.setActive(true)
try session.setCategory(AVAudioSession.Category.playback)
}catch {
print(error)
}
UIApplication.shared.beginReceivingRemoteControlEvents()
2、设置背景模式