It common practice to not include rich media content in a api response as the client will have to wait until everything has been sent which can take a long time. To speed up the process you should parser the information gathered and display that to the user while you have another asynchronously operation using a Block to retrieve the image and display it.
Get Spotify Track artwork on UITableView
-
18-06-2023 - |
Pergunta
I am trying to get artworks or album covers using spotify API. I am using:
NSString *url = @"http://ws.spotify.com/search/1/track.json";
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
([Utils isEmptyString:_searchBar.text] ? @"music" : _searchBar.text), @"q", nil];
[self sendRequestWith:url params:params method:RequestMethodGET success:^(AFHTTPRequestOperation *operation, id response, NSDictionary *userData) {
NSDictionary *result = (NSDictionary *)response;
if(result){
[_trackList removeAllObjects];
NSArray *tracks = [Utils getDictionaryValue:result by:@[@"tracks"]];
for (NSDictionary *trackData in tracks) {
WPTrack *track = [[WPTrack alloc] initWithSpotifyJSON:trackData];
[_trackList addObject:track];
}
[listViewController updateWithObjects:_trackList];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error, NSDictionary *userData) {
} userData:nil];
The current method I am getting doesn't seem to return the thumbnail of the track. But it returns "href" of the track which I can use to search for the track's image by https://embed.spotify.com/oembed/?url=spotify:track:6bc5scNUVa3h76T9nvpGIH. However, this might be another request which could slow my loading on the UITableView. Is there a better way to do this process together?
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow