区分app下载的app store地区

需要加入StoreKit.framework有app内置购买项目


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


http://stackoverflow.com/questions/2540530/how-to-detect-the-active-itunes-store-on-the-iphone-ipod-touch-ipad?lq=1

http://stackoverflow.com/questions/17523437/ios-programming-how-to-discover-from-which-countrys-app-store-the-app-was-d


区分手机设置所在地区

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值