简体   繁体   中英

Auto-renewable subscription, determine initial purchase

In the updatedtransactions method when the transactionState reflects the purchased state, I'd like to determine whether it's a new purchase or a renewal. Is this possible from the data? I couldn't find anything. I did see the originalTransaction but it says this is only defined for a restore, not a purchase. I could of course keep a flag in the app, but unfortunately I don't get information about when a subscription is cancelled. I could keep checking after each period whether it's renewed but there might be a slight gap there and this will get messy.

Thanks!

Verify the receipt as in http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/RenewableSubscriptions/RenewableSubscriptions.html . You get the original_purcahse_date_ms. Compare it to the purchase_date_ms... voila!

After your transactionState becomes purchasedState, you will want to verify the receipt as laid out in " Verifying an Auto-Renewable Subscription Receipt ".

You'll query the store and get a JSON response, which includes a receipt field - in this receipt is original_purchase_date. From what I understand, this is not the same as the transactionDate of the originalTransaction you found in your SKPaymentTransaction. The documentation says:

This holds the purchase date for the initial purchase; it represents the start date for the subscription.

If that query is also returning the very first subscription date, another approach would be to store this information on your own server, and validate the receipts there (mentioned at the very end of the section linked above).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM