iosswiftios10mpnowplayinginfocenter

MPMediaItemArtwork init(image:) deprecated in iOS 10.0


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?


Solution

  • 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.