【问题标题】:iPhone App: how to get app icon from app id?iPhone App:如何从应用程序ID获取应用程序图标?
【发布时间】:2012-12-22 15:38:13
【问题描述】:

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

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

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

我想得到这张图片:

【问题讨论】:

    标签: iphone ios itunes


    【解决方案1】:

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

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

    【讨论】:

    • H2CO3 numericIDStr 是 id,即 389801252 不是 id389801252
    • @InderKumarRathore 我不明白你的问题是什么。此代码有效(已测试)。
    • 抱歉错过了这一行NSString *numericIDStr = [idString substringFromIndex:2]; // @"389801252"
    • +1 @H2CO3 在搜索谷歌后我正要写这个答案,但你首先得到了这个。无论如何,我想知道为什么有1024x1024 (artworkUrl100) 图标。并认为它必须适用于视网膜 mac-book。
    • @InderKumarRathore 谢谢。好吧,Apple 有时会对使用 API 的开发人员开一些不太恰当的玩笑,我怀疑我们只是遇到了其中一个......
    【解决方案2】:

    仅供参考,您也可以使用应用的捆绑ID:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2014-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多