在运行时检测我的 iPhone 应用是从哪个国家的 App Store 下载的? [英] Detect at runtime which country's App Store my iPhone app was downloaded from?

查看:35
本文介绍了在运行时检测我的 iPhone 应用是从哪个国家的 App Store 下载的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iPhone 应用程序中有一项功能,出于商业原因,该功能应仅向美国客户显示/可用.如果我想将此应用发布到美国以外的 App Store,在不依赖用户定义的设置(例如语言和区域设置)的情况下,确定我所在国家/地区的最佳方法是什么?

I have a feature in my iPhone application that, for business reasons, should only be shown/available to customers in the US. If I want to release this app to App Stores outside the US, what's the best way to figure out which country I'm in without relying on user-defined settings such as language and locale?

在我看来,理想的解决方案是有一些运行时属性可以告诉我该应用是从哪个 App Store 国家/地区下载的,我可以采取相应的行动.浏览文档并搜索网络,我在这个部门没有任何想法.

In my mind, the ideal solution is that there's some runtime property that can tell me which App Store country the app was downloaded from, and I can take action accordingly. Looking through the docs and searching the web, I'm not coming up with anything in this department.

我不希望解决方案是 100% 万无一失的,只要用户不在他们所说的国家/地区,但尽可能靠近会很好.

I don't expect the solution to be 100% foolproof as far as users not being in the country they say they're from, but as close as possible would be nice.

我想一种解决方案是在 App Store 上为新产品单独构建并有两个版本,一个用于美国,一个用于其他版本,但这似乎并不理想.我希望它可以是 App Store 上的同一产品,以防止用户评论碎片化之类的事情.

I suppose one solution would be to make a separate build for a new product on the App Store and have two versions, one for the US and one for the others, but that doesn't seem ideal. I'm hoping it can be the same product on the App Store to prevent things like fragmentation of user reviews.

提前致谢!

推荐答案

我也认为使用 NSLocale 将是确定用户所在国家/地区的最佳解决方案.

I also think using NSLocale would be the best possible solution for determining the user's country.

这是怎么做的:

// Get user's country code based on currentLocale
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];

if ([countryCode isEqualToString:@"US"]){
    // US Only
}

但是,由于无法保证用户不会更改其国际设置,因此您可能别无选择,只能发布单独的应用程序,一个面向美国受众,另一个面向国际受众.

However, since there's no guarantee that the user won't change their international settings, you might have no choice but to release separate apps, one for a US audience and another for an international one.

这篇关于在运行时检测我的 iPhone 应用是从哪个国家的 App Store 下载的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆