【发布时间】:2016-01-07 21:09:57
【问题描述】:
这适用于 Swift 1,但在 Swift 2 中报告错误:
let image:UIImage = UIImage(named: getStringForLanguage(french: "lock_en", english: "lock_fr.") as! String)!
let albumArt = MPMediaItemArtwork(image: image)
let songInfo: NSMutableDictionary = [
MPMediaItemPropertyTitle: "",
MPMediaItemPropertyArtist: "",
MPMediaItemPropertyArtwork: albumArt
]
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo // this reports the error
错误信息:
无法将“NSMutableDictionary”类型的值分配给“[String : AnyObject]?”类型的值?
【问题讨论】:
-
只创建一个 Swift 字典,而不是 NSMutableDictionary。
-
如果工作,谢谢!最终代码: let songInfo: Dictionary = [ MPMediaItemPropertyTitle: "", MPMediaItemPropertyArtist: "", MPMediaItemPropertyArtwork: albumArt ] MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo
标签: ios swift2 mpnowplayinginfocenter