2014-09-23 10 views
5

L'immagine "UIImage" è sempre vuota ("null") sebbene la copertina sia visualizzata nell'app musicale da Apple. in iOS 7 funziona bene, ma con iOS 8 non ottengo alcuna copertura.MPMediaItemArtwork è nullo mentre la copertina è disponibile in iTunes

Cosa c'è di sbagliato con il mio codice, o cosa è cambiato in 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; 
} 

risposta

0

Il tuo codice sembra buono. Ho lo stesso codice per ottenere materiale illustrativo e funziona per me su iOS 8. SEI SICURO che l'elemento abbia effettivamente delle illustrazioni? Riproduci quella canzone nell'app musicale - artwork?

+0

sì, quando suono la stessa canzone o un album in app musicale, l'opera d'arte lì. – Meins

+0

artwork! = Nil MA immagine == nil c'è un problema con imageWithSize:? – Meins

+0

L'ho provato in un nuovo progetto, non funziona, qui il progetto http://www.file-upload.net/download-9572664/TestCover.zip.html – Meins

2

ho trovato il problema.

E'

CGSize artworkImageViewSize = CGSizeMake(100, 100); 

le seguenti opere:

CGSize artworkImageViewSize = CGSizeMake(120, 120); 

o

CGSize artworkImageViewSize = CGSizeMake(60, 60); 

tutto ciò che può essere diviso per 3 opere.

+0

Penso che troverete i multipli , a partire da 60. 60, 120, 240, 360 (?), 480 .... ecc. 90 non funzionerebbe, e nemmeno 360 lo farebbe. – topLayoutGuide

10

A partire da iOS 8, il selettore MPMediaItem di imageWithSize:(CGSize)size sembra non garantire che restituirà un'immagine. Se nessuna immagine viene restituito alla dimensione richiesta, chiamare di nuovo con la dimensione delle opere d'arte di proprietà bounds:

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

Questa dovrebbe essere la risposta accettata. – werm098

Problemi correlati