应用程序内购买:无法跟踪进程取消或成功

In App Purchase: Can not track process CANCEL or SUCCESS

当我在sandBox中使用IAP测试时,我有2种情况:

如何解决我的问题?如何知道用户是否取消? 谢谢!

更新: 当我在模拟器中测试时,当我取消 In App Purchase 请求 Apple ID 时 SKPaymentTransactionState 切换到 Failed

但是,当我在真实设备上测试时,当我取消 In App Purchase 请求 Apple ID 时,SKPaymentTransactionState 切换到 Purchasedtransaction.error总是nil.

我不知道为什么。

更新:

试试这个

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

更多,

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;
}