Ios Swift:远程指挥中心未显示在锁屏中
我试图在锁屏上显示指挥中心而不是为我工作, 我看到了本教程中的代码,并编写了相同的代码,但也不起作用 这是密码Ios Swift:远程指挥中心未显示在锁屏中,ios,swift,mpremotecommandcenter,Ios,Swift,Mpremotecommandcenter,我试图在锁屏上显示指挥中心而不是为我工作, 我看到了本教程中的代码,并编写了相同的代码,但也不起作用 这是密码 var nowPlayingInfo = [MPMediaItemPropertyTitle: currentPlaybackItem.trackName, MPMediaItemPropertyAlbumTitle: currentPlaybackItem.albumName,
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
任何人都可以帮助我注意到,当尝试更新now playing info dictionary时,您必须用数据填充键,即使是空字符串 你确定
trackName
,albumName
,artistName
不是零吗
有一个很好的例子:检查这个“正在播放”谢谢大家,
我找到了解决方案,我在集合类别中的最后一个代码
self.audioSession.setCategory(AVAudioSession.Category.playback , mode: .default , options: .mixWithOthers )
解决办法是
self.audioSession.setCategory(AVAudioSession.Category.playback , mode: .default , options: .init(rawValue: 0) )
这个图像存在吗?如果调用let块,是否调用
?您是否收到错误消息?是图像存在并在块中运行代码if let
是否使用UIBackgroundModes audio yes更新Info.plist我添加了背景模式“audio”提示:如果要说否选项,请使用选项:[
(您的解决方案在这种情况下有效,但如果存在枚举值0,您将使用该值而不是无值)