如何检测 iPhone/iPod Touch/iPad 上活动的 iTunes 商店?
我希望能够确定用户从我的应用程序内部连接到哪个商店,以便我可以引导他们找到适合其设备和商店的一些适当内容。有谁知道如何获取这些信息?
基本上,如果用户在英国,并连接到英国商店,我希望我的函数/方法返回 GB,如果在韩国,我想要 KR,澳大利亚 = AU 等。任何帮助将不胜感激。
I'd like to be able to determine which store the user connects to from inside my app, so that I can direct them to some appropriate content for their device AND store. Does anyone know how to get this information?
Basically, if the user is in the UK, and connects to the UK store, I want my function/method to return GB, if in Korea, I want KR, Australia = AU etc. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
获取用户区域设置的国家/地区代码的方法将起作用......但前提是用户的 iTunes 商店与其区域设置相同。情况并非总是如此。
如果您创建应用内购买项目,则可以使用 Apple 的 StoreKit API 来找出用户的实际 iTunes 国家/地区,即使它与用户的设备区域设置不同。这是一些对我有用的代码:
The approach of getting the country code of the user's locale will work ... but only if the user's iTunes store is the same as their locale. This won't always be the case.
If you create an in-app purchase item, you can use Apple's StoreKit APIs to find out the user's actual iTunes country even if it's different from their device locale. Here's some code that worked for me:
自 iOS 13.0 起,Apple 引入了 SKStorefront API。
它允许您检查用户当前连接到的 AppStore 国家/地区。
https://developer.apple.com/documentation/storekit/skstorefront
Since iOS 13.0, Apple introduced the SKStorefront API.
It allows you to check the current AppStore country the user is connected to.
https://developer.apple.com/documentation/storekit/skstorefront
到目前为止,您可以使用两种方法,各有优缺点:
StoreFront
->SDK >= 13
->三字母代码代表与该国家/地区相关的国家/地区App Store 店面
或
SKCloudServiceController
->从 iOS 9.3 开始可用。
->需要许可。在 tvOS 上,它可能会变得混乱,因为我找不到更改设置中权限的方法...
->许可文本相当混乱。
不要忘记将其包含在您的 .plist 文件中:
So far you can use 2 methods with their pros and cons:
StoreFront
->SDK >= 13
->The three-letter code representing the country associated with the App Store storefront
OR
SKCloudServiceController
-> Available from iOS 9.3.
-> Requires permission. On tvOS it can become messy as I can't find a way to change the permissions in settings...
-> Permission text quite confusing.
Don't forget to include that in your .plist file:
获得此功能的一个困难方法是为每个应用程序商店国家/地区设置一个应用程序。每个应用程序都拥有自己的国家/地区商店信息。这是假设用户坚持一家商店,这对大多数人来说应该是正确的。
A hard way to get this function is to set up up a single app for every app store country. Each app holds it's own country store information. This assumes, that a user sticks to one store, which should be true for most people.
我建议您尝试 iTunes 深层链接。例如,http://itunes.com/apps/appname 应将用户带到本地应用程序她花钱的商店。
I suggest you try iTunes deep links. For example, http://itunes.com/apps/appname should take the user to the local App Store where she spends money.
我需要相同的功能。目前,我正在考虑使用 NSLocale 中的数据作为默认值进行读取,但在 settings.app 中添加一个设置,以便用户在不匹配时进行自定义。
此函数取自 我的另一个问题的答案。
I need the same functionality. At the moment I'm considering reading using data from NSLocale as default, but adding a setting in settings.app for user to customise this if it does not match.
This function is taken from an answer to another question of mine.
您可能应该使用
这将返回像 en_US 或 en_UK 或 en_AU 甚至 zh_CN、zh_MY、jp_JP 等语言代码。
解析您支持的正确代码并相应地指导它们。
You should probably use
This will return a language code like en_US or en_UK or en_AU or even zh_CN, zh_MY, jp_JP and so on.
Parse the correct codes which you support and direct them accordingly.