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

时间:2022-11-11 22:58:28

I am looking for a way to get the app icon from the app id. Do you know how to do it? Please share the way. Thanks.

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

e.g 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:

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

我想得到这个图片:

1 个解决方案

#1


20  

(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. It might change in the future, but it doesn't seem to have changed in the near past, so here you are...

这可以使用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];

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. Feed this program an ID string (idString in the code above) and in the end, artworkImage will contain a UIImage with the desired image.

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

#1


20  

(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. It might change in the future, but it doesn't seem to have changed in the near past, so here you are...

这可以使用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];

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. Feed this program an ID string (idString in the code above) and in the end, artworkImage will contain a UIImage with the desired image.

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