Tho Nguyen Tho Nguyen - 2 months ago 13
iOS Question

In App Purchase: Can not track process CANCEL or SUCCESS

When I use IAP to test in sandBox, I have 2 case:


  • Case 1: If I buy item successfully.
    transaction.state
    switch to
    Purchased
    key.

  • Case 2: If I cancel when Iphone asking me to login Apple ID or accept the payment.
    transaction.state
    switch to
    Purchased
    key too.



How to solve my problem? how to know user cancel or not?
Thank you!

UPDATE:
When I test in simulator, the
SKPaymentTransactionState
switch to
Failed
when I cancel In App Purchase request Apple ID.

But, when I test in real device, the
SKPaymentTransactionState
swtich to
Purchased
when I cancel In App Purchase request Apple ID. The
transaction.error
always
nil
.

I don't know why.

UPDATE:


  • I can't track TransactionState because I have used my boss device which has been jailbreak and use Local validate Receipt . OMG.

  • Thank you for your helping


Answer

try this

if (transaction.error.code == SKErrorPaymentCancelled)
    {
            NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
    }

For more,

switch (transaction.error.code) {
    case SKErrorUnknown:
        //Unknown error
        break;
    case SKErrorClientInvalid:
        // client is not allowed to issue the request, etc.
        break;
    case SKErrorPaymentCancelled:
        // user cancelled the request, etc.
        break;
    case SKErrorPaymentInvalid:
        // purchase identifier was invalid, etc.
        break;
    case SKErrorPaymentNotAllowed:
        // this device is not allowed to make the payment
        break;
    default:
        break;
}
Comments