MKStoreKit icon indicating copy to clipboard operation
MKStoreKit copied to clipboard

kMKStoreKitProductPurchasedNotification doesn't contain the transactionState. It's required to determine whether the product is purchases or restored.

Open funnel20 opened this issue 10 years ago • 2 comments

When calling [[MKStoreKit sharedKit] restorePurchases] to restore earlier purchases, I was under the impression that only kMKStoreKitRestoredPurchasesNotification would be fired. However, for each product kMKStoreKitProductPurchasedNotification is fired too (before kMKStoreKitRestoredPurchasesNotification). The current notification object is only 'transaction.payment.productIdentifier'. So there is no way in kMKStoreKitProductPurchasedNotification to determine whether the product is purchased or restored. For several purposes I want to know that.

I have solved this by using the complete SKPaymentTransaction as object to kMKStoreKitProductPurchasedNotification:

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

Instead of:

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

SKPaymentTransaction contains the property "transactionState".

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 transactionState via:

SKPaymentTransactionState transactionState = transaction.transactionState;

The latter can be compared to SKPaymentTransactionStatePurchased or SKPaymentTransactionStateRestored.

funnel20 avatar Sep 21 '15 12:09 funnel20

Nice addition @funnel20. I'm adding this to my branch.

warpling avatar Oct 16 '15 21:10 warpling

Shifting to this in my branch too.

tjaved avatar Nov 03 '15 08:11 tjaved