b2cloud

25th October 2013

In App Purchase store changes in StoreKit

Guides | Tutorial By 3 years ago

Something I often see with pretty much every app on the AppStore with In App Purchases is that they don’t update prices if I login with an account linked to a different store than the one the prices have already loaded for.

I was facing the same problem in my app, where if you had previously loaded say, $AUD prices then logged in with a UK account, the $AUD prices would still be there. If the user wanted to see the price for their region they would need to close the app completely and reopen it to get the correct prices. Not the optimal user experience.

I set off to find a solution. Unfortunately there’s no simple “Store did change” notification to observe. In the end I did find a solution, not as obviously as I would have liked, but it gets the job done, and I’m confident there’s no other solutions out there (correct me if I’m wrong).

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for(SKPaymentTransaction* transaction in transactions)
    {
        NSError* transactionError = transaction.error;

        if(transactionError != nil && transactionError.code == SKErrorUnknown)
        {
            NSLog(@"User potentially switched stores");
            [self refreshAllProductInfo];
        }
    }
}

I have watched closely to what happens when the user switches stores, and the unknown error code is set on the transactions that failed. You can listen for this with the code above (obviously add yourself as a transaction observer) and when you get that unknown error, refresh your products.

I haven’t seen any other cases where the unknown error is used, but it could obviously result in refreshing your prices even if they haven’t changed store, but I think because it’s a better experience for the user, it’s a worthwhile feature.

Recommended Posts

MKMapView: determining whether region change is from user interaction

Post by 3 years ago

Knowing whether an MKMapView‘s region has changed by the user or by other means seems to be asked time and time again. I’ve seen various solutions. Most of them come down to adding your own

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!