iPhone应用程序:如何从应用程序ID获取应用程序图标?

时间:2012-12-22 15:38:14

标签: iphone ios itunes

我正在寻找一种从应用ID中获取应用图标的方法。你知道怎么做吗?请分享方式。感谢。

e.g Instagram,我正在寻找的ID是:id389801252

https://itunes.apple.com/jp/app/instagram/id389801252?mt=8

我想得到这张图片:

enter image description here

3 个答案:

答案 0 :(得分:21)

(我在谷歌搜索2分钟后写了这个答案......这只是正确关键字的问题!)

可以使用iTunes Store的未记录的 documented API。它可能会在未来发生变化,但在近期似乎没有变化,所以在这里你是......

NSString *idString = @"id389801252";

NSString *numericIDStr = [idString substringFromIndex:2]; // @"389801252"
NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", numericIDStr];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *json = [NSData dataWithContentsOfURL:url];

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];
NSArray *results = [dict objectForKey:@"results"];
NSDictionary *result = [results objectAtIndex:0];
NSString *imageUrlStr = [result objectForKey:@"artworkUrl100"]; // or 512, or 60

NSURL *artworkURL = [NSURL URLWithString:imageUrlStr];
NSData *imageData = [NSData dataWithContentsOfURL:artworkURL];
UIImage *artworkImage = [UIImage imageWithData:imageData];

请注意,这会使用NSURL API执行两次同步往返,因此您最好将其包装在backgorund线程中以获得最佳用户体验。为此程序提供一个ID字符串(上面的代码中为idString),最后,artworkImage将包含一个带有所需图像的UIImage。

答案 1 :(得分:0)

仅供参考,您也可以使用该应用程序的捆绑软件ID:

http://itunes.apple.com/lookup?bundleId=com.burbn.instagram

答案 2 :(得分:0)

不确定这是否完全相关,但是Apple提供了iTunes Link Maker工具。如果使用此工具查找您的应用程序,还将在显示“应用程序图标”部分的位置看到它。单击embed,然后从那里获取img链接。需要注意的一件事是,我最终还是稍微使用了URL来找到所需的正确大小和格式(例如,您可以获取jpg渲染而不是png或选择任意大小,例如128x128)

相关问题