我需要获取当前激活的iTunes商店国家代码。我已阅读有关获取当前语言环境的信息,但这不是非常智能的解决方案,因为用户可以拥有一个语言环境,但完全不同的iTunes帐户。解决方案不需要合法,苹果拒绝在这里不是问题。有没有人使用私有框架找到了这个场景的解决方案?获取当前iTunesStore国家
1
A
回答
2
您可以在通过检查产品的priceLocale之一上的NSLocale请求商店的产品后执行此操作。试试这个代码:
- (NSString*) storeCountryCode:(NSArray*) products
{
NSString* countryCode = nil;
SKProduct* product = [products objectAtIndex:0];
if(product != nil)
{
NSLocale* storeLocale = product.priceLocale;
countryCode = (__bridge NSString*)CFLocaleGetValue((__bridge CFLocaleRef)storeLocale, kCFLocaleCountryCode);
}
return countryCode;
}
你可以从你的SKProductsRequestDelegate方法称之为:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSString* storeCountryCode = [self storeCountryCode:response.products];
//other product handling
}
0
可以 “CFLocaleGetValue” 把这种使用
NSString *aCountry=[getCurrentItunesStoreCountryFromProudct:myProudct];
-(NSString *)getCurrentItunesStoreCountryFromProudct:(SKProduct *)aProudct
{
NSLocale* storeLocale = aProudct.priceLocale;
NSString *storeCountry = (NSString*)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);
return storeCountry;
}
0
您可以获取Storefront ID与此代码。由于它依赖私有API,因此不要在生产代码中使用。
NSError *error = nil;
BOOL loaded = [[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/iTunesStore.framework"] loadAndReturnError:&error];
if (loaded) {
NSString *localStoreFrontID = nil;
@try {
localStoreFrontID = [NSClassFromString(@"ISClient") valueForKeyPath:@"currentClient.localStoreFrontID"];
}
@catch (NSException *exception) {
NSLog(@"%@", exception);
}
NSLog(@"localStoreFrontID: %@", localStoreFrontID);
}
else {
NSLog(@"Error: %@", error);
}
在iOS 5.1.1上,为我打印localStoreFrontID: 143459-2,2
,即瑞士商店。我不确定-2,2
后缀是什么意思,也许是关于语言。我没有在iOS 6上进行过测试。
请注意,它在您通过设置→存储退出帐户后仍然有效。
+0
我在运行6.1的设备上测试过。 localStoreFrontID返回null。 – XCool
相关问题
- 1. Android:获取当前国家offiline
- 2. 获取当前国家/地区名称
- 3. 错误获取当前的国家
- 4. Moodle php获取当前用户国家
- 5. 如何获取用户当前国家电话区号前:+966
- 6. 在Android中获取国家的国家
- 7. 获取当前所有国家的时间
- 8. IOS获取用户当前国家可靠
- 9. 如何根据当前位置获取国家代码?
- 10. 如何获取视图区域的当前国家?
- 11. 如何从iPhone的核心位置获取当前(美国)国家?
- 12. 从国家选择器隐藏当前国家
- 13. 获得一个国家的国家当一个国家被选中
- 14. 获取ISO国家代码
- 15. 获取国家名称android
- 16. Swift - 获取国家列表
- 17. C++获取国家代码
- 18. 从经度获取国家
- 19. 从jVectormap获取国家onregionclick
- 20. 获取用户的国家
- 21. 从tzInfo TimeZone获取国家?
- 22. Magento:按国名获取国家代码
- 23. 获取给定的美国国家
- 24. 不同国家的当前时间-Xamarin
- 25. C#和当前不同国家/地区的当前时间
- 26. 从国家/地区代码获取国家/地区名称
- 27. C#:从国家代码获取国家名称
- 28. 使用Google API获取城市的国家/国家建议
- 29. 从国家代码在python中获取国家名称?
- 30. 从国家代码中获取国家/地区名称
是的,这是解决方案,但该应用程序将与企业许可证生产,并inAppPurchase不允许,对不对? –
在App Store中不存在企业应用程序,因此不能在应用程序购买中使用 – Daniel