我目前正在开发适用于iOS的广播应用。为了节省时间,我的伙伴给我发了他的工作代码来获取iTunes专辑封面以及相应的头文件。我的问题是,在构建应用程序时,我收到错误,指出JSON与ARC不兼容。这个特定问题有不同的解决方法吗?
以下是我现在使用的代码:
NSString *searchURL = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=music&limit=1", xxxx];
NSData *searchData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[searchURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
BOOL bAlbumArtAdded = NO;
NSDictionary *searchDict = [searchData objectFromJSONData];
NSArray *searchResults = [searchDict objectForKey:@"results"];
if (searchResults != nil)
{
if ([searchResults count] > 0)
{
NSDictionary *searchResult = [searchResults objectAtIndex:0];
if ([searchResult objectForKey:@"artworkUrl100"] != nil)
{
NSString *viewURL = [NSString stringWithFormat:@"%@", [[searchResult objectForKey:@"artworkUrl100"] substringFromIndex:0]];
NSString *albumDescription = [NSString stringWithFormat:@"%@", [[searchResult objectForKey:@"copyright"] substringFromIndex:0]];
NSString *viewURL170 = [viewURL substringToIndex:([viewURL length] - 14)];
NSString *viewURLNEW = [NSString stringWithFormat:@"%@170x170-75.jpg", viewURL170];
NSLog(@"This is image url: %@",viewURLNEW);
NSLog(@"This is image url: %@",albumDescription);
[_coverImage setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:viewURLNEW]]]];
bAlbumArtAdded = YES;
}
}
}
if (!bAlbumArtAdded)
{
// [_coverImage setImage:[_radioLogo objectAtIndex:playerIndex]];
}