ios iTunes api,通过捆绑 ID 查找?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8839328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:15:41  来源:igfitidea点击:

iTunes api, lookup by bundle ID?

iphoneiosmobileitunes

提问by rynop

Is there any way to use the iTunes APIto lookup information based on the unique app bundleId? I have an iphone app, I want to use the API to check to see if the user has the newest version. Using the search sucks, cuz its fuzzy (can return lots of results). I'd prefer not to have to iterate over the result set looking for my bundleId..

有什么方法可以使用iTunes API根据唯一的应用程序bundleId 查找信息吗?我有一个 iphone 应用程序,我想使用 API 来检查用户是否有最新版本。使用搜索很糟糕,因为它很模糊(可以返回很多结果)。我宁愿不必遍历结果集以查找我的 bundleId ..

I'm not looking for a way to do this on the device side (not objective c). I'd like to make server side code on my server that hides when/if apple makes API change.

我不是在寻找在设备端执行此操作的方法(不是目标 c)。我想在我的服务器上制作服务器端代码,当/如果苹果进行 API 更改时隐藏。

回答by Roman Blachman

Apple has changed their API, and removed the language code from the URL, so you should only the bundleIdfor the app you are looking for. For example:

Apple 已经更改了他们的 API,并从 URL 中删除了语言代码,因此您应该只bundleId为您正在寻找的应用程序添加语言代码。例如:

http://itunes.apple.com/lookup?bundleId=com.yelp.yelpiphone

http://itunes.apple.com/lookup?bundleId=com.yelp.yelpiphone

In addition, you can add the country parameter to the query, to get results for a specific country App Store.

此外,您可以在查询中添加国家/地区参数,以获取特定国家/地区 App Store 的结果。

For example:

例如:

http://itunes.apple.com/lookup?bundleId=com.yelp.yelpiphone&country=de

http://itunes.apple.com/lookup?bundleId=com.yelp.yelpiphone&country=de

The description, user rating and other fields might change between different App Store countries.

不同 App Store 国家/地区之间的描述、用户评分和其他字段可能会有所不同。

回答by rynop

Turns out you can use the 'Apple ID' instead of the bundle ID as it is also unique per app. The 'Apple ID' maps to 'trackId' in http://itunes.apple.com/lookupservice.

事实证明,您可以使用“Apple ID”而不是捆绑 ID,因为它对于每个应用程序也是唯一的。“Apple ID”映射到http://itunes.apple.com/lookup服务中的“trackId” 。

回答by Adam

You can use a bundle id with Search API. Just replace idwith bundleId, like following:

您可以将捆绑 ID 与Search API 一起使用。只需替换idbundleId,如下所示:

http://itunes.apple.com/lookup?bundleId=com.facebook.Facebook

http://itunes.apple.com/lookup?bundleId=com.facebook.Facebook

EDIT: As @Roman Blachman stated, the country code logic has changed. If you want to limit your results to a specific country, use the following example.

编辑:正如@Roman Blachman 所说,国家/地区代码逻辑已更改。如果要将结果限制在特定国家/地区,请使用以下示例。

http://itunes.apple.com/lookup?bundleId=com.facebook.Facebook&country=us

http://itunes.apple.com/lookup?bundleId=com.facebook.Facebook&country=us

回答by Scott Bossak

You can use the library, iVersion, to see if the user has the latest version of the app from within the app.

您可以使用库iVersion来查看用户是否在应用程序中拥有最新版本的应用程序。

iVersion

Library for dynamically checking for updates to Mac/iPhone App Store apps from within the application and notifying users about the new release. Can also notify users about new features in the app the first time they launch after an upgrade.

https://github.com/nicklockwood/iVersion

版本

用于从应用程序内动态检查 Mac/iPhone App Store 应用程序更新并通知用户新版本的库。还可以在升级后首次启动时通知用户有关应用程序中的新功能。

https://github.com/nicklockwood/iVersion

回答by Gurjinder Singh

Thanks to all above answers. Here is code in swift 4.2

感谢以上所有答案。这是swift 4.2中的代码

guard let info = Bundle.main.infoDictionary,
            let identifier = info["CFBundleIdentifier"] as? String,
      let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") else { return }
    do {
      let data = try Data(contentsOf: url)
      guard let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any] else {
        return
      }
      if let result = (json["results"] as? [Any])?.first as? [String: Any],
        let version = result["version"] as? String {
        print("version in app store", version)
      }
    } catch let erro as NSError {
      print(erro.description)
    }