Find locale currency for iphone programmatically

前端 未结 7 447
攒了一身酷
攒了一身酷 2020-12-02 05:20

I want to find out the currency locale on user\'s iphone programmatically. That means, if user is in US Store, the currency locale should be USD, for Australia, it should be

相关标签:
7条回答
  • 2020-12-02 06:23

    thanks for your answer. I finally figured out that I can retrieve the price and the currency code directly from Apple:

    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {    
        NSArray *products = response.products;
        if (products && products.count != 0) {
            product = [products objectAtIndex:0];
            [[NSNotificationCenter defaultCenter] postNotificationName:PRICE_UPDATED object:product.LocalizedPrice];    
        } 
    
        // finally release the reqest we alloc/init’ed in requestProUpgradeProductData
        [productsRequest release];
    }
    
    
    
    @implementation SKProduct (LocalizedPrice)
    
    - (NSString *)LocalizedPrice
    {
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
        [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
        [numberFormatter setLocale:self.priceLocale];
        NSString *formattedString = [numberFormatter stringFromNumber:self.price];
        [numberFormatter release];
        return formattedString;
    }
    
    @end
    
    0 讨论(0)
提交回复
热议问题