如何检测 iPhone/iPod Touch/iPad 上活动的 iTunes 商店?

发布于 2024-08-27 00:23:27 字数 154 浏览 7 评论 0原文

我希望能够确定用户从我的应用程序内部连接到哪个商店,以便我可以引导他们找到适合其设备和商店的一些适当内容。有谁知道如何获取这些信息?

基本上,如果用户在英国,并连接到英国商店,我希望我的函数/方法返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

酒废 2024-09-03 00:23:27

获取用户区域设置的国家/地区代码的方法将起作用......但前提是用户的 iTunes 商店与其区域设置相同。情况并非总是如此。

如果您创建应用内购买项目,则可以使用 Apple 的 StoreKit API 来找出用户的实际 iTunes 国家/地区,即使它与用户的设备区域设置不同。这是一些对我有用的代码:

- (void) requestProductData
{
    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:
                                 [NSSet setWithObject: PRODUCT_ID]];
    request.delegate = self;
    [request start];
}

- (void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    NSArray *myProducts = response.products;
    for (SKProduct* product in myProducts) {
        NSLocale* storeLocale = product.priceLocale;
        storeCountry = (NSString*)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);
        NSLog(@"Store Country = %@", storeCountry);
    }

    [request release];

    // If product request didn't work, fallback to user's device locale
    if (storeCountry == nil) {
        CFLocaleRef userLocaleRef = CFLocaleCopyCurrent();
        storeCountry = (NSString*)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode);
    }

    // Now we're ready to start creating URLs for the itunes store
    [super start];
}

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:

- (void) requestProductData
{
    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:
                                 [NSSet setWithObject: PRODUCT_ID]];
    request.delegate = self;
    [request start];
}

- (void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    NSArray *myProducts = response.products;
    for (SKProduct* product in myProducts) {
        NSLocale* storeLocale = product.priceLocale;
        storeCountry = (NSString*)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);
        NSLog(@"Store Country = %@", storeCountry);
    }

    [request release];

    // If product request didn't work, fallback to user's device locale
    if (storeCountry == nil) {
        CFLocaleRef userLocaleRef = CFLocaleCopyCurrent();
        storeCountry = (NSString*)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode);
    }

    // Now we're ready to start creating URLs for the itunes store
    [super start];
}
最好是你 2024-09-03 00:23:27

自 iOS 13.0 起,Apple 引入了 SKStorefront API。

它允许您检查用户当前连接到的 AppStore 国家/地区。

SKStorefront:包含 Apple App Store 店面的位置和唯一标识符的对象。

概述

您通过 App Store Connect 创建的应用内产品可在每个拥有 App Store 的地区销售。您可以使用店面信息来确定客户所在的区域,并提供适合该区域的应用内商品。您必须维护自己的产品标识符列表以及要在其中提供这些标识符的店面。

主题

  • 国家/地区代码:代表与 App Store 店面关联的国家/地区的三字母代码。
  • 标识符:Apple 定义的值,用于唯一标识 App Store 店面。

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.

SKStorefront: An object containing the location and unique identifier of an Apple App Store storefront.

Overview

In-app products you create through App Store Connect are available for sale in every region with an App Store. You can use the storefront information to determine the customer's region, and offer in-app products suitable for that region. You must maintain your own list of product identifiers and the storefronts in which you want to make them available.

Topics

  • countryCode: The three-letter code representing the country associated with the App Store storefront.
  • identifier: A value defined by Apple that uniquely identifies an App Store storefront.

https://developer.apple.com/documentation/storekit/skstorefront

你在看孤独的风景 2024-09-03 00:23:27

到目前为止,您可以使用两种方法,各有优缺点:

StoreFront

->SDK >= 13

->三字母代码代表与该国家/地区相关的国家/地区App Store 店面

if let storeFront = SKPaymentQueue.default().storefront{
    print("StoreFront CountryCode = ", storeFront.countryCode)
}
else {
    print("StoreFront NOT Available")
}

SKCloudServiceController

->从 iOS 9.3 开始可用。

->需要许可。在 tvOS 上,它可能会变得混乱,因为我找不到更改设置中权限的方法...

->许可文本相当混乱。

let skCloudServiceController = SKCloudServiceController()
SKCloudServiceController.requestAuthorization { (status) in
    guard status == .authorized else {
        return
    }

    skCloudServiceController.requestStorefrontCountryCode(completionHandler: { (countryCode, error)  in
        if let error = error {
            print("Failure: ", error)
        }
            else if let countryCode = countryCode {
            print("Country code: ", countryCode)
        }
    })
}

不要忘记将其包含在您的 .plist 文件中:

<key>NSAppleMusicUsageDescription</key>
<string>Store information</string>

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

if let storeFront = SKPaymentQueue.default().storefront{
    print("StoreFront CountryCode = ", storeFront.countryCode)
}
else {
    print("StoreFront NOT Available")
}

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.

let skCloudServiceController = SKCloudServiceController()
SKCloudServiceController.requestAuthorization { (status) in
    guard status == .authorized else {
        return
    }

    skCloudServiceController.requestStorefrontCountryCode(completionHandler: { (countryCode, error)  in
        if let error = error {
            print("Failure: ", error)
        }
            else if let countryCode = countryCode {
            print("Country code: ", countryCode)
        }
    })
}

Don't forget to include that in your .plist file:

<key>NSAppleMusicUsageDescription</key>
<string>Store information</string>
风向决定发型 2024-09-03 00:23:27

获得此功能的一个困难方法是为每个应用程序商店国家/地区设置一个应用程序。每个应用程序都拥有自己的国家/地区商店信息。这是假设用户坚持一家商店,这对大多数人来说应该是正确的。

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.

饭团 2024-09-03 00:23:27

我建议您尝试 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.

情仇皆在手 2024-09-03 00:23:27

我需要相同的功能。目前,我正在考虑使用 NSLocale 中的数据作为默认值进行读取,但在 settings.app 中添加一个设置,以便用户在不匹配时进行自定义。

此函数取自 我的另一个问题的答案

- (NSString *)getUserCountry
{
    NSLocale *locale = [NSLocale currentLocale];
    return [locale objectForKey: NSLocaleCountryCode];
}

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.

- (NSString *)getUserCountry
{
    NSLocale *locale = [NSLocale currentLocale];
    return [locale objectForKey: NSLocaleCountryCode];
}
绝情姑娘 2024-09-03 00:23:27

您可能应该使用

[[userDefaults dictionaryRepresentation] objectForKey:@"NSLocaleCode"];

这将返回像 en_US 或 en_UK 或 en_AU 甚至 zh_CN、zh_MY、jp_JP 等语言代码。

解析您支持的正确代码并相应地指导它们。

You should probably use

[[userDefaults dictionaryRepresentation] objectForKey:@"NSLocaleCode"];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文