如何检测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];
}