restoreCompletedTransactionsFailedWithError: Error Code 0 (SKErrorUnknown) on Cancel

随声附和 提交于 2020-01-02 10:04:43

问题


So basically, I want to display an alert when the restoring of completed transactions fails for some network/iTunes-specific reason, but not when the user taps 'Cancel' on the Apple ID/Password prompt.

In my implementation of:

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error

...I am testing error.code against SKErrorPaymentCancelled (perhaps I should also test against SKErrorPaymentNotAllowed, but that's not relevant now).

Still, the alert showed anyway when tapping 'cancel'. NS-Logging its value showed that error.code == 0 (i.e., SKErrorUnknown).

This is happening on iOS 4.3.1, Xcode 4.2, build 4C199 (sandbox store, of course).

I have checked similar questions, but what is answered there is not what is happening in my case (that is, what I'm already doing should yield the correct behavior)... Any ideas?


回答1:


Check against these. Should be enough.

// error codes for the SKErrorDomain
enum {
    SKErrorUnknown,
    SKErrorClientInvalid,       // client is not allowed to issue the request, etc.
    SKErrorPaymentCancelled,    // user cancelled the request, etc.
    SKErrorPaymentInvalid,      // purchase identifier was invalid, etc.
    SKErrorPaymentNotAllowed    // this device is not allowed to make the payment
};

From https://stackoverflow.com/a/9017990/129202.

So what I do is I do a switch on the error.code, and only show an error when the code is not SKErrorPaymentCancelled. The user probably knows he/she pushed the cancel button (when entering user/pass).

So SKErrorPaymentCancelled should catch the cancel. If cancel button throws another error code, then there's a problem with that iOS version?




回答2:


I've found that on iOS Simulator, cancelling fails with error code 0 (SKErrorUnknown). But if you run it on the device, it correctly returns SKErrorPaymentCancelled. This seems to apply on iOS 9 as well.



来源:https://stackoverflow.com/questions/11537053/restorecompletedtransactionsfailedwitherror-error-code-0-skerrorunknown-on-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!