Expires_date field for renewable iOS subscription

When checking for a renewable subscription, I try to get the expiration date of the last receipt.

In accordance with the apple documentation for the receipt field, the field "expires_date" should contain a number that represents milliseconds from January 1, 1970, 00:00:00 GMT. ( https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1 )

When I get the field, but I get the string with the formatted date from the "expires_date" field. There is another field called "expires_date_ms" that appears to provide the correct data. Apple claims that "Keys not described below are reserved for use by Apple and must be ignored by your application."

Here is an example of my receipt:

{"quantity":"1", "product_id":"com.testapp.test", "transaction_id":"1000000135676121", "original_transaction_id":"1000000135134855", "purchase_date":"2014-12-15 06:53:54 Etc/GMT", "purchase_date_ms":"1418626434059", "purchase_date_pst":"2014-12-14 22:53:54 America/Los_Angeles", "original_purchase_date":"2014-12-15 06:51:12 Etc/GMT", "original_purchase_date_ms":"1418626272000", "original_purchase_date_pst":"2014-12-14 22:51:12 America/Los_Angeles", "expires_date":"2014-12-15 06:56:10 Etc/GMT", "expires_date_ms":"1418626570000", "expires_date_pst":"2014-12-14 22:56:10 America/Los_Angeles", "web_order_line_item_id":"1000000028947356", "is_trial_period":"false" }] 

Which field should be used to get expiration dates using best practices?

+5
source share
1 answer

As you found, the documentation for " expires_date " at this link ...

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1

... states Keys not described below are reserved for use by Apple and must be ignored by your application. However, he now says that " expires_date " is an ASN.1 Field Value IA5STRING, interpreted as RFC 3339 date .

It seems that today (2015-12-04), a year after your question, Apple has not yet specified and made the official field " expires_date_ms ", which clearly indicates the milliseconds representing " expires_date ".

As you will also find, the receipt contains the version of _ms and _pst . _pst clearly corresponds to the time zone of PST or America / Los_Angeles.

 receipt":{"receipt_type":"ProductionSandbox", "adam_id":0, "app_item_id":0, "bundle_id":"com.my.cool.app", "application_version":"1.0.3", "download_id":0, "version_external_identifier":0, "receipt_creation_date":"2015-12-04 03:48:00 Etc/GMT", "receipt_creation_date_ms":"1449200880000", "receipt_creation_date_pst":"2015-12-03 19:48:00 America/Los_Angeles", "request_date":"2015-12-04 03:53:45 Etc/GMT", "request_date_ms":"1449201225187", "request_date_pst":"2015-12-03 19:53:45 America/Los_Angeles", "original_purchase_date":"2013-08-01 07:00:00 Etc/GMT", "original_purchase_date_ms":"1375340400000", "original_purchase_date_pst":"2013-08-01 00:00:00 America/Los_Angeles", "original_application_version":"1.0", "in_app":[ {"quantity":"1", "product_id":"com.my.cool.app.inapppurchase1", "transaction_id":"1000000000000589", "original_transaction_id":"1000000000000589", "purchase_date":"2015-12-03 08:09:32 Etc/GMT", "purchase_date_ms":"1449130172000", "purchase_date_pst":"2015-12-03 00:09:32 America/Los_Angeles", "original_purchase_date":"2015-12-03 08:09:34 Etc/GMT", "original_purchase_date_ms":"1449130174000", "original_purchase_date_pst":"2015-12-03 00:09:34 America/Los_Angeles", "expires_date":"2015-12-03 08:14:32 Etc/GMT", "expires_date_ms":"1449130472000", "expires_date_pst":"2015-12-03 00:14:32 America/Los_Angeles", "web_order_line_item_id":"1000000031087708", "is_trial_period":"false"}, "latest_receipt_info":[ {"quantity":"1", "product_id":"com.my.cool.app.inapppurchase1", "transaction_id":"1000000000000589", "original_transaction_id":"1000000000000589", "purchase_date":"2015-12-03 08:09:32 Etc/GMT", "purchase_date_ms":"1449130172000", "purchase_date_pst":"2015-12-03 00:09:32 America/Los_Angeles", "original_purchase_date":"2015-12-03 08:09:34 Etc/GMT", "original_purchase_date_ms":"1449130174000", "original_purchase_date_pst":"2015-12-03 00:09:34 America/Los_Angeles", "expires_date":"2015-12-03 08:14:32 Etc/GMT", "expires_date_ms":"1449130472000", "expires_date_pst":"2015-12-03 00:14:32 America/Los_Angeles", "web_order_line_item_id":"1000000031087708", "is_trial_period":"false"}, "latest_receipt":"MIItbAYJKoZIhvcNAQcCoIItXTCCLV...truncated...nA=="} 

However, until ios release changes its wording or list of fields, it is not recommended, however, to use the _ms and _pst fields .

+1
source

Source: https://habr.com/ru/post/1209063/


All Articles