ImageWithSize Flakey with MPMediaItemArtwork in iOS8

In my application, I am showing an album cover on a button. On iPhone 5, the size of the button limiter is 273x269.5. My design code has always been very simple and nothing has changed.

MPMediaItem *currentItem = [musicPlayer nowPlayingItem];
MPMediaItemArtwork *iTunesArtwork = [currentItem valueForProperty: MPMediaItemPropertyArtwork];

CGSize buttonBounds = self.albumArtworkButton.bounds.size;
UIImage *resizedImage = [iTunesArtwork imageWithSize: CGSizeMake (buttonBounds.width, buttonBounds.height)];

      

Suddenly as of iOS8 doing this result will result in resizedImage = nil. What's really weird is that if I change the last line, execute the following line:

UIImage *resizedImage = [iTunesArtwork imageWithSize: CGSizeMake (300, 300)];

      

results in a valid image (i.e. resizedImage is not null and the image can be displayed).

Any ideas what might be causing this? I didn't change anything, but the code broke.

+3


source to share


1 answer


I see this new bug in iOS8 with my apps. This only happened for some of the covers and it depended on what size my target was. the error seems to have something to do with it, it cannot reduce the image by some factor. For example I have some 600x600 images from iTunes and when I try to get a 100x100 imageWithSize it returns nil trying to get a 200x200 image size image. I have one 200x203 image and 100x100 doesn't work, 101x101 doesn't work but 102x102 will work - I thought maybe the highest resolution you wanted should be greater than 1/2 of the original measurement to avoid error but that turned out to be not true based on 600x600 images running at 200x200. possibly,is it a shared memory change or something - it's hard to see why the error occurs when you don't have the source anyway, so I stopped guessing and used this workaround. basically just use the original bounds of the MPMediaItemArtwork object when you request the UIImage via imageWithSize. Then make sure the UIImageView you are using with the UIImage has contentMode to display the image correctly (UIViewContentModeScaleAspectFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleToFill).when you request UIImage via imageWithSize. Then make sure that the UIImageView you are using with the UIImage has contentMode to display the image correctly (UIViewContentModeScaleAspectFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleToFill).when you request UIImage via imageWithSize. Then make sure that the UIImageView you are using with the UIImage has contentMode to display the image correctly (UIViewContentModeScaleAspectFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleToFill).



// display album artwork
MPMediaItemArtwork* artwork = [representativeItem valueForProperty:MPMediaItemPropertyArtwork];
CGRect bounds = [artwork bounds];
UIImage* artworkImage = [artwork imageWithSize:bounds.size];
if (artworkImage)
{
    [cell.imageView setImage:artworkImage];
}
else
{
    [cell.imageView setImage:[UIImage imageNamed:@"AlbumDefault.png"]];
}

      

+4


source







All Articles