Is there a way to get the SKProduct from an SKPayment in the StoreKit API?

in-app-purchase, ios, objective-c, storekit

Solution

I don't think it is possible right now to get that information from the the SKPaymentTransaction or its SKPayment object.

You could query this information though by setting up a SKProductRequest with one or more product identifiers. The response is handled by productsRequest:didReceiveResponse.

Apple's documentation has a pretty good example of how to do it here.

Problem

Given an `SKPaymentTransaction` is there a way to get the `SKProduct`? I'm trying to implement a generic `SKPaymentTransactionObserver` that will allow my app to be notified of all in-app purchases that occur. I have implemented the `SKPaymentTransactionObserver` interface, and I am getting the `paymentQueue: updatedTransactions:` callback firing correctly. In my callback I have access to the `SKPaymentTransaction` object, and from there I can get the `SKPayment` object. From the payment I cannot find a way to get the `SKProduct` though. This is frustrating since the `SKPayment` must have been created using the `SKProduct`, but the interface only allows the user to get the `productIdentifier`. To create an SKPayment Really, I want to get access to the cost, quantity, and local currency that was spent, and these are properties of the `SKProduct`. The only way I can see to do this is to swizzle [SKPayment paymentWithProduct:]` and intercept payment creation, which is an awful prospect.

Original source