MPMediaItemArtwork init (image :) is deprecated in iOS 10.0

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

the class shows an interface, showing below the method available in the new OS version

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

Does anyone know how to use it?

Also question 2, part of the previous question: does metadata display on the locked screen and control center using MPNowPlayingInfoCenter in the simulator?

+5
source share
2 answers

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, the metadata display is β€œnow playing” in the control center in the simulator.

+20
source

I saw this now, and I'm confused too, but I think this is the right way:

 self.remoteArtwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:CGSizeMake(600, 600) requestHandler:^UIImage * _Nonnull(CGSize size) { UIImage *lockScreenArtworkApp = [UIImage imageNamed:@"lockScreenLogo"]; return [self.manager resizeImageWithImage:lockScreenArtworkApp scaledToSize:size]; }]; 

Method - in my case in a singleton "Manager" -Class

 - (UIImage *)resizeImageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { //UIGraphicsBeginImageContext(newSize); // In next line, pass 0.0 to use the current device pixel scaling factor (and thus account for Retina resolution). // Pass 1.0 to force exact pixel size. UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } 
+3
source

Source: https://habr.com/ru/post/1261411/


All Articles