Reputation: 8493
I'm trying to create a custom 'ad' for one of our own additional apps in appstore. Everything is working perfectly, but in the ad we are now writing NSLog(@"For only $0.99");
How can I make this a variable based on the local 'logged in' appstore? I'm thinking it should look something like this:
NSString *price = [something localPriceForTier:1];
NSLog(@"For only %@", price);
And it'd say whatever currency and value it is where the user is based on that the Price Tier I'm sending is 1. I think I've seen apps with this before, but I have no idea what to search for regarding this.
Upvotes: 2
Views: 1092
Reputation: 7845
As far as I know, Store Kit doesn't have any function to ask for generic price tier. You have to ask for the current local price of one of your products. Here's some code:
- (void) requestProductData
{
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:
[NSSet setWithObject: yourProductIdentifier]];
request.delegate = self;
[request start];
}
The callback function:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *myProducts = response.products;
SKProduct *product = [myProducts objectAtIndex:0];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
NSString *formattedString = [numberFormatter stringFromNumber:product.price];
NSLog(@"For only %@", formattedString);
}
The above snippets are explained in detail in the official In-App Purchase Programming Guide: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008267
Upvotes: 2
Reputation: 100632
That information isn't kept on the device, it's something you have to fetch if you want it. So what you want to do is create an SKProductsRequest
with the appropriate product identifiers (which you can get from iTunes Connect), wait until your delegate gets a suitable SKProductsResponse
from which you can obtain the appropriate SKProduct
and you can use the price
and priceLocale
from there with a number formatter to get a string of the local price with the appropriate currency symbol. There's a quick bit of sample code in the SKProduct
documentation.
Upvotes: 1