3

In my app, I display album artwork on a button. On an iPhone 5, the button bounds size is 273x269.5. My code to size the artwork has always been very straightforward 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 with iOS8, the execution of this results in resizedImage = nil. What is really strange is that if I change the last line, the execution of the following line:

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

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

Any ideas what might cause this? I haven't changed anything, but the code broke.

JeffB6688
  • 3,782
  • 5
  • 38
  • 58

1 Answers1

4

I'm seeing this new bug in iOS8 with my apps also. It was only happening for some of the coverart and it depended on what my target size was. it seems the bug has something to do with it can't reduce an image by some factor. For example I have some images from iTunes that are 600x600 and when I try to get an imageWithSize of 100x100 it returns nil while trying to get an imageWithSize of 200x200 works. I have one image that is 200x203 and 100x100 doesn't work, 101x101 doesn't work, but 102x102 will work - I thought maybe the highest resolution you wanted needed to be more than 1/2 of the original dimension to avoid the bug but that didn't turn out to be true based on the 600x600 images working at 200x200. perhaps its the total memory size change or something like that - anyway it's hard to figure out why a bug happens when you don't have their source 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 use with the UIImage has it's contentMode set to display the image properly (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"]];
}
Richie Hyatt
  • 2,244
  • 2
  • 21
  • 14
  • Setting contentMode on the imageView doesn't solve the problem for me. Do you have any other tricks up your sleeve? Manually resizing the originally sized image is painfully slow, unfortunately. – wstr Jul 08 '15 at 17:15