MPMediaItemArtwork is null while cover is available in iTunes

前端 未结 3 1551
慢半拍i
慢半拍i 2020-12-18 04:00

The UIImage \"image\" is always empty (\"null\") though the cover is shown in the music app by apple. in iOS 7 it works fine, but with iOS 8 I get no cover.

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 04:54

    As of iOS 8, MPMediaItem's selector imageWithSize:(CGSize)size appears to not guarantee that it will return an image. If no image is returned at the requested size, call it again with the size of the artwork bounds property:

    MPMediaItemArtwork *artwork = [self valueForProperty:MPMediaItemPropertyArtwork];
    UIImage *image = [artwork imageWithSize:size];
    if (image == nil) {
        image = [artwork imageWithSize:artwork.bounds.size];
    }
    

提交回复
热议问题