iPhone 应用程序 : how to get app icon from app id?

标签 iphone ios itunes

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

例如 Instagram,我要找的id是:id389801252

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

我想得到这张图片:

enter image description here

最佳答案

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

这可以使用未记录 documented iTunes Store 的 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 执行两个同步往返,因此您最好将其包装在后台线程中以获得最大的用户体验。为该程序提供一个 ID 字符串(上面代码中的 idString),最后,artworkImage 将包含一个带有所需图像的 UIImage。

关于iPhone 应用程序 : how to get app icon from app id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14004087/

相关文章:

iphone - 枚举崩溃时,GyroUpdates和重新启动场景发生了变化(SpriteKit和Swift)

ios - 使用 Swift 按字母顺序对 TableView 单元格进行排序

Xcode 项目图标文件和 Organizer Archives 图稿

iphone - 从 iPhone 应用程序链接到播客的选项有哪些?

ios - 使用搜索在 App 内启动 iTunes Store

iphone - 设置 body 后如何设置 NSMutableRequest 超时小于 240 秒?

iphone - iPhone 应用程序上的 Facebook 登录

iphone - 在标签上设置文本时出现 iOS 6 问题

ios - 同时支持 iOS 6 和 iOS 7 的应用程序

ios - Swift 3 Table View - 从某些单元格中删除堆栈 View