evenodd
evenodd

Reputation: 2126

High number of users fail to purchase my IAP. Is this to be expected?

After adding analytics to my app, I have seen a very high number of users reach an error when trying to purchase a product within my app. Not all fail though.

.03% of all my users reach the error .002% of my users successfully purchase the product

It's been very hard for me to debug because when I test with different devices and different apple accounts, the purchase always succeeds.

The error event is called when either 0 SKProducts can be found (they must have no internet?), or when they attempt to purchase, the transaction reads SKPaymentTransactionStateFailed.

My question is, how should I go about debugging this? What is the normal percentage of users that fail to purchase a product (maybe their iCloud isn't setup correctly, or their payment is declined). I still get a relatively normal amount of revenue from the IAP, so clearly it is working for some people. Am I really missing out on all these purchases due to a bug, or is something else going on?

My purchase code looks like this. I am using a pod called IAPHelper. I am highly doubtful the pod is the problem, since I've switched it out and had the same results.

- (void)makePurchase {

    SKProduct* product =[[IAPShare sharedHelper].iap.products objectAtIndex:0];
    [[IAPShare sharedHelper].iap buyProduct:product
                               onCompletion:^(SKPaymentTransaction* trans){

        if(trans.error){
            [self showErrorPurchasing:trans.error];
        } else if(trans.transactionState == SKPaymentTransactionStatePurchased) {
            [[IAPShare sharedHelper].iap provideContentWithTransaction:trans];
            [self purchaseSucceeded];
        } else if(trans.transactionState == SKPaymentTransactionStateFailed) {
            [self showErrorPurchasing:trans.error];
        } else if(trans.transactionState == SKPaymentTransactionStateDeferred) {
            [self hideHud];
        } else if(trans.transactionState == SKPaymentTransactionStateRestored) {
            [self purchaseSucceeded];
        }
    }];
}

Thank you

Upvotes: 1

Views: 123

Answers (2)

Dinithi De Silva
Dinithi De Silva

Reputation: 1182

Your users might have cancelled the purchase without continuing. In that case, you will receive purchase failed state.

Check whether the error code 2, to identify a user purchase cancel event. Here's how I handle it in my swift project. Hope this helps.

case .failed:
let errorCode = (trans.error as? SKError)?.code
if (errorCode == .paymentCancelled) {
   //Handle cancelled purchase
}

Upvotes: 0

skaak
skaak

Reputation: 3018

I can't answer your question directly but in terms of the code maybe this will help. When you do

SKProduct* product =[[IAPShare sharedHelper].iap.products objectAtIndex:0];

the objectAtIndex will crash if the array is empty. Either test the array to make sure it has products or use firstObject and then test if firstObject is nil. So in summary

SKProduct * product = [... firstObject];

if ( product )
{
  ... your code ...
}
else
{
  ... unable to read products / no connection ...
}

Upvotes: 1

Related Questions