-1

How to get iPhone app price in code for US store? Like 0.99$ or Free

Is there any Objective-C code helps?

I want present today rate.

Here is one similar question: Programmatically identify if an app is paid or free In this they suggested to parse itc link, but I don't know how to parse..

Is there any simple way?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nav
  • 467
  • 4
  • 18

2 Answers2

6

To satisfy your curiosity you can use the iTunes Search API:

NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/lookup?id=412828831"]]; // add &country=XX for specific country, default is US
if (jsonData) {
    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    NSArray *results = json[@"results"];
    NSDictionary *firstResult = [results firstObject];

    NSLog(@"\"%@\" is currently available for %@(%@)", firstResult[@"trackName"], firstResult[@"formattedPrice"], firstResult[@"price"]);
}

In your real app you can check if the bundle identifier matches to the identifier of your ad-supported app:

if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.myname.myapp.withAds"]) {
    // show ads
}
else {
    // don't show ads

}

You want to avoid to send useless requests to the network. That costs battery life and in some cases (contracts that have a volume limit) money. The bundle identifier would be the better choice.

I would hardcode it completely by using preprocessor macros. Because in this case I don't have to deliver advertising frameworks. Apple started to reject apps that use the advertisingIdentifier without displaying ads. And shipping an advertising SDK, which uses the advertisingIdentifier (i.e. any advertising SDK), with an app that is not supposed to display ads might lead to rejection.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
1

You should generally not be trying to query the store directly (though there is an API available and you would use NSNumberFormatter for display purposes). Instead, use SKStoreProductViewController to present information on the products you are interested in.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • not inAp purchase price, main app price. Please post code – Nav Feb 11 '14 at 12:12
  • `SKStoreProductViewController` is used to display store items, not in-app purchases. What are you actually trying to do from a user point of view? – Wain Feb 11 '14 at 12:14
  • in back end, if present rate is free then show ads, if paid then dont show ads. So I just want to know rate. – Nav Feb 11 '14 at 12:16
  • 1
    So you want to show ads to users that have paid for your app, just because the app is currently free? Prepare for some bad reviews. – Matthias Bauch Feb 11 '14 at 12:18
  • nope..we are not changing rate once released...free and pro two apps. I want to know in code present rate.. – Nav Feb 11 '14 at 12:19
  • 1
    I agree with @MatthiasBauch. If your rate is set for each app, code the app to do appropriate things, don't hit the network to try to get information about the app that you already have statically at build time – Wain Feb 11 '14 at 12:20
  • ok agree, macro helps. For curiosity, is there any way to find present rate of app programmatically with SKStoreProductViewController ? – Nav Feb 11 '14 at 12:23
  • `SKStoreProductViewController` abstracts you from details like that. You need to use the iTunes JSON interface to get that kind of detail. – Wain Feb 11 '14 at 12:26