MPRemoteCommandCenter在swift 4中出错

Iam*_*yne 6 avfoundation swift mpremotecommandcenter

我正在尝试设置我的应用程序以使用MPRemoteCommandCenter.我从文档编程指南中得到了这个例子.我导入AVFoundation甚至尝试导入AVKIT,我收到错误使用未解析的标识符'MPRemoteCommandCenter'.当我创建MPRemoteCommandCenter.shared()的实例时.任何帮助,将不胜感激.

func setupRemoteTransportControls() {

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()   Error //**Use of unresolved identifier 'MPRemoteCommandCenter'**

    // Add handler for Play Command
    commandCenter.playCommand.addTarget { [unowned self] event in
        if self.audioPlayer.rate == 0.0 {
            self.audioPlayer.play()
            return .success
        }
        return .commandFailed
    }

    // Add handler for Pause Command
    commandCenter.pauseCommand.addTarget { [unowned self] event in
        if self.audioPlayer.rate == 1.0 {
            self.audioPlayer.pause()
            return .success
        }
        return .commandFailed
    }
}
Run Code Online (Sandbox Code Playgroud)

Rhy*_*man 19

你需要 import MediaPlayer