0

I have an in-app purchase for my app that costs £1.99. I display this price using a pop-up, however, when the device is not connected to the internet it cannot retrieve the price of my IAP, so it shows up blank.

The price of my IAP will always be £1.99 GBP. How do I display this IAP tier for other countries when the device is not connected to the internet?

This is how I currently get the price of my IAP:

_products = nil;
        [[AppIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
            if (success) {
                _products = products;

                SKProduct * product = _products[0];

                [[AppIAPHelper sharedInstance] productPurchased:product.productIdentifier];

                NSNumberFormatter *_priceFormatter = [[NSNumberFormatter alloc] init];
                [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
                [_priceFormatter setLocale:product.priceLocale];
                priceString = [_priceFormatter stringFromNumber:product.price];

                NSLog(@"Price string: %@",priceString);
            }
        }];

I tried to test if priceString.count <= 0 (therefore device is not connected to the internet), and then execute:

NSDecimalNumber *amount = [NSDecimalNumber decimalNumberWithString:@"1.99"];
NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"AmountSo with symbol: %@", [currencyFormat stringFromNumber:amount]);//Eg: $50.00
NSLog(@"Current Locale : %@", [locale localeIdentifier]);//Eg: en_US

But this only adds the local currecy symbol to amount.

The problem is, I need to display the correct price tiers. For example, USD 1.99 converted to GBP is 1.27. But the IAP tiers are 1.99 USD and 1.49 GBP.

So basically - how do I show the App Store IAP price tiers for the user's local currecy without requesting the price of the SKProduct (if the user is not connected to the internet)? Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
BadBoolean
  • 35
  • 7
  • Do not assume your IAP will always be 1.99. You may change your mind or Apple could change the price someday. And as "remus" asks in their answer, why do this? If the app has no Internet access you should not be showing the user anything about IAP since you can't perform any IAP without Internet access. – rmaddy Nov 18 '14 at 04:26

1 Answers1

2

You could create a property list (plist), static NSDictionary, or some other relational table containing the current price tiers mapped to country codes. If no network connection is available, grab the current locale country and use it to look up the price tier and local currency symbol.

Question though: since you can't make an in-app purchase without a network connection, why exactly do you care? Just throw a notification stating that network connection is unavailable?

One more option you could have, if you want it to be somewhat robust, is set it to cache using a policy that refreshes it if network is available, otherwise uses the cached copy. Something like this using Reachability would work, though admittedly this is for an NSURLRequest not an SKProduct request.

Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if (netStatus == ReachableViaWiFi)
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
else
    [request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
Community
  • 1
  • 1
brandonscript
  • 68,675
  • 32
  • 163
  • 220