MugunthKumar / MKStoreKit

The "Goto" In App Purchases Framework for iOS 8+
2.09k stars 430 forks source link

kMKStoreKitProductPurchaseFailedNotification doesn't contain the error object. It's required to determine whether the user pressed Cancel (error.code == SKErrorPaymentCancelled) #246

Open funnel20 opened 9 years ago

funnel20 commented 9 years ago

On an error I'd like to show an Alert to the user. However, when he presses cancel on one of the App Store Alerts (like entering App Store credentials), this kMKStoreKitProductPurchaseFailedNotification is also send. If he presses Cancel I don't want to show an Alert. In other words I need to now the error code.

To do so, I changed the following line:

[[NSNotificationCenter defaultCenter] postNotificationName:kMKStoreKitProductPurchaseFailedNotification
                                                      object:transaction.payment.productIdentifier];

in:

[[NSNotificationCenter defaultCenter] postNotificationName:kMKStoreKitProductPurchaseFailedNotification
                                                      object:transaction];

by using the complete SKPaymentTransaction as object.

When receiving the notification in a class, the transaction ID can be retrieved via:

SKPaymentTransaction *transaction = [notification object];
NSString *id = transaction.payment.productIdentifier;

And the error code via:

NSInteger code = transaction.error.code;

The latter can be compared to SKErrorPaymentCancelled.