如何检测iPhone / iPod Touch / iPad上的活动iTunes商店? [英] How to detect the active iTunes store on the iPhone/iPod Touch/iPad?

查看:151
本文介绍了如何检测iPhone / iPod Touch / iPad上的活动iTunes商店?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

基本上,如果用户在英国,并连接到英国商店,我希望我的函数/方法返回GB ,如果在韩国,我想要KR,澳大利亚= AU等。任何帮助都将受到赞赏。

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.

推荐答案

获得用户区域设置的国家/地区代码将起作用...但仅当用户的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.

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

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];
}

这篇关于如何检测iPhone / iPod Touch / iPad上的活动iTunes商店?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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