简体   繁体   English

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

[英]iPhone App: how to get app icon from app id?

I am looking for a way to get the app icon from the app id.我正在寻找一种从应用程序 ID 获取应用程序图标的方法。 Do you know how to do it?你知道怎么做吗? Please share the way.请分享方法。 Thanks.谢谢。

eg Instagram, where the id I'm looking for is: id389801252例如 Instagram,我要查找的 id 是:id389801252

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

I want to get this image:我想得到这个图像:

在此处输入图片说明

(I composed this answer after 2 minutes of googling... It's just the matter of the correct keyword!) (我在谷歌搜索 2 分钟后撰写了这个答案......这只是正确关键字的问题!)

This is possible using an undocumented documented API of the iTunes Store.这可以使用 iTunes Store 的未记录文档API 来实现。 It might change in the future, but it doesn't seem to have changed in the near past, so here you are...它在未来可能会改变,但它似乎在不久的过去没有改变,所以你在这里......

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];

Note that this performs two synchronous round-trips using the NSURL API, so you better wrap this in a backgorund thread for maximal user experience.请注意,这使用NSURL API 执行两个同步往返,因此您最好将其包装在 backgorund 线程中以获得最大的用户体验。 Feed this program an ID string ( idString in the code above) and in the end, artworkImage will contain a UIImage with the desired image.订阅该程序的ID字符串( idString并且在最后在上面的代码), artworkImage将包含所需的图像一个UIImage。

Just for reference, you can use the app's bundle id too:仅供参考,您也可以使用应用程序的捆绑包 ID:

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

Not sure if this is at all relevant anymore, but Apple provides an iTunes Link Maker tool.不确定这是否完全相关,但 Apple 提供了一个iTunes Link Maker工具。 If you use this tool to find your app, you'll also see where it shows an App Icon section.如果您使用此工具查找您的应用程序,您还会看到它显示应用程序图标部分的位置。 Click embed and grab the img link from there.单击embed并从那里获取 img 链接。 One thing to note, I did end up playing with the url a bit to find the right size and format I needed (for instance you can get a jpg render instead of png or select an arbitrary size like 128x128)需要注意的一件事,我最终使用了 url 来找到我需要的正确大小和格式(例如,您可以获得 jpg 渲染而不是 png 或选择任意大小,如 128x128)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM