代码之家  ›  专栏  ›  技术社区  ›  Iam Wayne

swift 4中的MPRemoteCommandCenter错误

  •  9
  • Iam Wayne  · 技术社区  · 8 年前

    我正在尝试将我的应用程序设置为使用MPRemoteCommandCenter。我从文档编程指南中得到了这个示例。我导入了AVFoundation,甚至尝试导入AVKIT,我发现了错误 使用未解析的标识符“MPRemoteCommandCenter” 。创建MPRemoteCommandCenter实例时。共享()。任何帮助都将不胜感激。

    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
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  30
  •   Gordon Childs    8 年前

    你需要 import MediaPlayer