How to get locale currency price for in-app purchases in iOS? How to get locale currency price for in-app purchases in iOS? objective-c objective-c

How to get locale currency price for in-app purchases in iOS?


productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:prodcutIdentifier];    productsRequest.delegate = self;        // This will trigger the SKProductsRequestDelegate callbacks    [productsRequest start];

This will call your delegate function. Once the above is done, it will automatically call the below mentioned function finally. This is where the app store request sent will be finalized.

(void)requestDidFinish:(SKRequest *)request{           SKProduct *book = [Books objectAtIndex:0];            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];    [numberFormatter setLocale:book.priceLocale];        NSLocale* storeLocale = book.priceLocale;    NSString *storeCountry = (NSString*)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);    }

provide the Locale and country details as per your interest.


Here book is the SKProduct:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];[numberFormatter setLocale:book.priceLocale];NSString *formattedPrice = [numberFormatter stringFromNumber:book.price];NSLog(@"%@", formattedPrice);

simply ask if anything unclear!

Regards,


One line of code:

product is the SKProduct object instance:

NSString *price = [NSString stringWithFormat:@"%@%@ %@", [product.priceLocale objectForKey:NSLocaleCurrencySymbol], product.price, [product.priceLocale objectForKey:NSLocaleCurrencyCode]];

Results:

$1.39 USD