MPMediaItemArtwork为空,而封面在iTunes中可用

Mei*_*ins 6 null cover artwork mpmediaitem ios

UIImage"图像"始终是空的("零"),虽然盖在苹果公司的音乐应用程序中.在iOS 7中,它运行良好,但在iOS 8中我没有封面.

我的代码有什么问题,或者iOS 8中有什么变化?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumCell"];
    MPMediaItemCollection *song = self.songsList[indexPath.row];

    cell.albumName.text = [[song representativeItem] valueForProperty: MPMediaItemPropertyAlbumTitle];

    cell.albumArtist.text = [[song representativeItem] valueForProperty:MPMediaItemPropertyAlbumArtist];


    CGSize artworkImageViewSize = CGSizeMake(100, 100);
    MPMediaItemArtwork *artwork = [song valueForProperty:MPMediaItemPropertyArtwork];
    UIImage *image = [artwork imageWithSize:artworkImageViewSize];

    NSLog(@"-------------------");
    NSLog(@"%@",[[song representativeItem] valueForProperty: MPMediaItemPropertyAlbumTitle]);
    NSLog(@"%@",image);

    if (artwork) {

        cell.cover.image = image;
    }
    else
    {
        cell.cover.image = [UIImage imageNamed:@"nocover.png"];
    }

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

Ric*_*tos 11

从iOS 8开始,MPMediaItem选择器imageWithSize:(CGSize)size似乎无法保证它将返回图像.如果没有以请求的大小返回图像,请使用artwork bounds属性的大小再次调用它:

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


mar*_*ing 0

你的代码看起来不错。我有相同的代码来获取艺术品,它在 iOS 8 上适用于我。您确定该项目确实有艺术品吗?在音乐应用程序中播放那首歌 - 艺术作品?