In App Purchase Not Working in iOS? Here is a solution

Swarnendu De April 30, 2014

While browsing for In App Purchase tutorials, I found these two very useful blogs:

  1. In App Purchases: A Full Walkthrough

  2. Introduction to In-App Purchases in iOS 6 Tutorial

If you are a beginner you would find the first blog very useful. There is already existing library for in app purchase . Ronan O’Ciosoig has suggested to use RMStore for ease and I found that RMStore  is helpful for quick implementation of in app purchase.

However, after going through both the blogs, I did not find any answer on what to do when In App Purchase does not work. I took some points from here and there, figured out some ways on my own and finally solved the problem.

In this blog, I would talk about the possible issues that may hamper in app purchase process and would also talk about possible solutions.

1. The functionality runs on Device not on Simulator:

In App Purchase does not work in simulator for some specific reasons, it not even fetches the product details or product list from server. So, before running the app , please check the target device setting in your IDE and make sure it points to Device.

2. Product ID invalid :

The product ID of a certain product may show invalid for the following reasons  (courtesy: itsme.manish and abgtan from the forums):

  • Go to SettingsiTunes & App Stores, log out of any account, and try again so you’re sure you’re using a Sandbox account.

  • Check this link – if it doesn’t respond, the iTunes sandbox may be down.

  • Have you enabled In-App Purchases for your App ID?

  • Does your project’s .plist Bundle ID match your App ID?

  • Are you using the full product ID when when making an SKProductRequest?

  • Have you waited several hours since adding your product to iTunes Connect?

  • Are your bank details active on iTunes Connect?

  • Have you tried deleting the app from your device and reinstalling?

N. B. – Right convention for product naming is to put the full bundle Id followed by a “.” before the product name. For example, assume your project bundle identifier is “com.innofied.SampleProject”, then the product name should be “com.innofied.SampleProject.ProductName”.  Copy the product Id showed on apple website, and paste it in appropriate place of your project. Most of the people get Invalid product due to this specific reason.

3.  Restore Product Purchased:

In case non-consumable product, Apple strictly mentions to keep a restore button.

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

You should add transaction observer at init method . You should do it in “buyProduct:” or “restoreTransactions:” method.  It is the best practice.

4. Remove Transaction observer on observer method calling:

Whenever you add an transactionObserver , it is your duty to remove it. If you don’t, it will create some issues like apple account login screen may appear without any reason. Several developers come across this specific problem. So, you should remove transaction observer on observer method call. like following :

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
   ...

   [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

   ...
}

#pragma mark completed Transactions call back
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
   ...

   [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

   ...
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error{
   ...

   [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

   ...
}
- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions{
   ...

   [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

   ...
}

 

5. Use new provisioning profile :

Sometimes people run their app with the existing ‘wildchar’  identifier in provisioning profile but it does not support In App Purchase. To test in app purchase you should create a new provisioning profile dedicated to the specific app and add it to the app.

Hope this helps. If you ever come up with any other issues while implementing In App Purchase features, feel free to comment here and we will help you find a realistic solution.