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)