Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKPaymentTransactionStateFailed, but no NSError

We have an app with IAP coin purchases. We've recently received mails from a few of our users, saying that they couldn't purchase any coins. I looked at their session logs and saw Failed IAP events, each with no fail reason logged. Here's the related code:

- (void)_purchaseRequestFailed:(SKPaymentTransaction *)transaction state:(StoreTransactionState)state error:(NSError *)error
{
    IAPProduct *product = [self getProductWithId:transaction.payment.productIdentifier];
    if (error.code==SKErrorPaymentCancelled) {
        [_metricsManager logFailIAP:product failReason:@"Payment canceled"];
    } else {
        [_metricsManager logFailIAP:product failReason:error.localizedDescription];
    }
    if ([_delegate respondsToSelector:@selector(didSucceedPurchasingProduct:)]) {
        [_delegate didFailPurchasingProduct:product];
    }
}

inside logFailIAP, I log things like time, UDID, event name, and the error.localizedDescription.

 if (failReason != nil && failReason.length > 0) {
        [metricsDictionary setObject:failReason forKey:MetricsEventParameterFailReason];
 }

In the logs, I'm getting Failed IAP events, but no logged reason for failing. Is there any case where, you get "SKPaymentTransactionStateFailed", but, have an empty error.localizedDescription? I can confirm that the logs work, and have seen errors like "Payment canceled", and "Cannot connect to iTunes" being logged in other devices. The issue is not specific to a device or iOS.

like image 840
Matt1636 Avatar asked Mar 15 '13 06:03

Matt1636


1 Answers

I have encountered a nil error in the following scenario:

  • User updates iOS on their device.

  • Immediately after the update, the user goes into your app and tries to make a purchase.

  • Instead of the usual purchase dialog, they get an "iTunes terms of service have changed. You need to accept new T&C's" (or something along the lines), which redirects them to the iTunes app and shows them the new T&C's. The payment is then cancelled and you get a nil error, and, obviously, a nil error.localizedDescription.

For this scenario to happen, your app needs to be the user's first point of interaction with the iTunes Store after the system update.

like image 76
Alexey Blinov Avatar answered Oct 26 '22 10:10

Alexey Blinov