Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 511
Marc O'Morain Avatar asked Mar 25 '14 14:03

Marc O'Morain


People also ask

What is SKProduct?

An object containing the subscription period duration information. enum SKProduct.PeriodUnit. Values representing the duration of an interval, from a day up to a year.

What is Apple StoreKit?

StoreKit provides a simple and secure way to purchase digital goods or services in your apps across all Apple platforms, so people can start playing, gaming, reading, and more, right away.


2 Answers

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.

like image 174
Alicia Cano Avatar answered Sep 30 '22 02:09

Alicia Cano


Given an SKPaymentTransaction is there a way to get the SKProduct?

You could get the productIdentifier from the transaction object from which you can get the product info if you have an array of SKProducts by looking up the array for productIdentifier,

transaction.payment.productIdentifier
like image 43
Nagendra Rao Avatar answered Sep 30 '22 02:09

Nagendra Rao