MPMediaItemArtwork init(image:) deprecated in iOS 10.0

carbonr picture carbonr · Dec 16, 2016 · Viewed 7.4k times · Source

Apple has deprecated init(image:) method in MPMediaItemArtwork in iOS 10. What is the new alternative.

the class shows interface shows method below to be available in the new OS version

public init(boundsSize: CGSize, requestHandler: @escaping (CGSize) -> UIImage)

Anyone know how to use it?

Also question 2, part of the previous question: Does showing now playing metadata on the lock-screen and control-center using MPNowPlayingInfoCenter work in the simulator?

Answer

Virasio picture Virasio · Dec 20, 2016

You can use the following code:

let image = UIImage(named: "logo")!
let artwork = MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
        return image
})

And, yes, "now playing" metadata shows on the control center in the simulator.