ios - Swift:远程命令中心不显示在 lockScreen 中

标签 ios swift mpremotecommandcenter

我正在尝试在锁定屏幕中显示命令中心而不是为我醒来, 我看到了本教程中的代码,并编写了相同的代码但也无法正常工作 https://github.com/lukagabric/LGAudioPlayerLockScreen

这是代码

  var nowPlayingInfo = [MPMediaItemPropertyTitle: currentPlaybackItem.trackName,
                          MPMediaItemPropertyAlbumTitle: currentPlaybackItem.albumName,
                          MPMediaItemPropertyArtist: currentPlaybackItem.artistName,
                          MPMediaItemPropertyPlaybackDuration: audioPlayer.duration,
                          MPNowPlayingInfoPropertyPlaybackRate: NSNumber(value: 1.0 as Float)] as [String : Any]

    if let image = UIImage(named: currentPlaybackItem.albumImageName) {
        nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(image: image)
    }
    self.nowPlayingInfoCenter.nowPlayingInfo = nowPlayingInfo

任何人都可以提供帮助

最佳答案

我注意到在尝试更新正在播放的信息字典时,您必须用数据填充键,即使是空字符串也是如此。

你确定 trackName, albumName, artistName 不是 nil 吗?

ModernAVPlayer有一个很好的例子:检查这个“NowPlaying”code

关于ios - Swift:远程命令中心不显示在 lockScreen 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53986069/

相关文章:

ios - 安装 cocoapods 时出错 : Failed to build gem native extension

ios - 聊天应用程序中彩色背景的奇怪形状

ios - 防止AVPlayerController劫持MPRemoteCommandCenter

swift - 快速锁定屏幕上的命令中心洗涤器

ios - 我的应用内购买如何满足批量购买计划?

ios - UITileLayer 显示忽略伪造的图层大小

ios - 在应用商店(应用内)方法上评分 - 错误 : "Your request produced an error. [newNullLineResponse]". 重新提交新应用

ios - 我可以在 Swift Playground 中加载 Alex Voice吗

ios - SKCropNode 在 Xcode 7 + Swift 2 中无法正常工作

ios - 如何在控制中心显示 "live"(swift iOS)