3

Searched for answer to this all over, can't find an answer.

I have an app with IAP. If the user is not logged into iTunes, they get a login prompt.

If they cancel from the Login prompt, I get a callback to failedTransaction:transaction but the error code is 0 (which is enum as SKErrorUnknown).

So how do I distinguish between a cancel and another SKErrorUnknown, one of which is being in Airplane mode? (If they are in airplane mode the error code is also 0).

I want to provide an alert in this case, but not if they hit Cancel.

Again - before someone misreads my question - the answer to this is NOT to test for SKErrorPaymentCancelled = 2.

You get this code when the user cancels the PURCHASE AFTER the login.

But I'm asking about cancelling the login.

EDIT - maddy, really? here's my code:

/**************************************************************************
 paymentQueue
 **************************************************************************/
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction * transaction in transactions) {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    };
}

/**************************************************************************
 failedTransaction
 *************************************************************************/
- (void)failedTransaction:(SKPaymentTransaction *)transaction {

    NSLog(@"error code = %ld", transaction.error.code);

    // If IAP fails, display an alertView.
    NSString *title = @"Purchase Failed";
    NSString *messageString = @"In-app Purchased failed. Could not contact iTunes store or iTunes login not valid";

    if (transaction.error.code != SKErrorPaymentCancelled) {
        UIAlertView *iapFailedAlertView = [[UIAlertView alloc] initWithTitle:title message:messageString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [iapFailedAlertView show];
        iapFailedAlertView = nil;
    }

    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

see anything I'm doing wrong?

  • I just ran some tests and if I tapped Cancel on any of the sign-in or login dialogs, I get failed transaction with an error code of `SKErrorPaymentCancelled` (2), not `SKErrorUnknown` (0). – rmaddy Feb 01 '14 at 18:44
  • maddy - see EDIT above. with this code I'm getting "error code = 0" in the console. – user1673403 Feb 01 '14 at 20:40
  • UPDATE: I was getting error code 0 when the authentication dialog already had the iTunes ID filled in and it's asking for fingerprint (Touch ID), and hit Cancel. But when I log out of the account and the authen. dialog has the blank fields to log in, and hit Cancel, then I get error code = 2. Strange. Sound like a bug? Or do I need to listen for a different message? – user1673403 Feb 01 '14 at 20:53
  • That might be a bug. I don't have a 5s so I can't test this myself. You should put together a little test app that demos the problem and submit a bug report to Apple. In the meantime you will have to work around the bug. – rmaddy Feb 01 '14 at 20:55
  • ok, thanks. Another update is that when I turn off touch ID for app purchases, and the dialog comes up where you have to put type in the password, and I hit Cancel, then I get error code 2. So it seems to be specific to the Touch ID authentication dialog. yes, I think this is a bug so I'll report it. – user1673403 Feb 01 '14 at 20:57

0 Answers0