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?