Swiftystorekit: How to get details out of the latest receipt?

Created on 27 Jan 2016  路  3Comments  路  Source: bizz84/SwiftyStoreKit

Specifically I need to extract the expires_date information from the latest receipt.

I have auto renewing subscriptions and I want to monitor when the subscription expires.

question

Most helpful comment

I use this function:

func expirationDateFromResponse(jsonResponse: [String: AnyObject]) -> NSDate? {

    if let receiptInfo: NSArray = jsonResponse["latest_receipt_info"] as? NSArray {

        let lastReceipt = receiptInfo.lastObject as! NSDictionary
        let formatter = NSDateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"

        let expirationDate: NSDate =
        formatter.dateFromString(lastReceipt["expires_date"] as! String) as NSDate!

        return expirationDate

    } else {

        return nil

    }
}

While passing the receipt:

let expirationDate = expirationDateFromResponse(receipt)

All 3 comments

I have not tested yet because I have not renewed my apple subscription but in theory after call the receipt verification method you receive in Success a ReceiptInfo = [String: AnyObject]

You can access this dico directly with "expitation_date" key
Or you can use ReceiptInfoField.expitation_date.rawValue
all key are described here https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1

I use this function:

func expirationDateFromResponse(jsonResponse: [String: AnyObject]) -> NSDate? {

    if let receiptInfo: NSArray = jsonResponse["latest_receipt_info"] as? NSArray {

        let lastReceipt = receiptInfo.lastObject as! NSDictionary
        let formatter = NSDateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"

        let expirationDate: NSDate =
        formatter.dateFromString(lastReceipt["expires_date"] as! String) as NSDate!

        return expirationDate

    } else {

        return nil

    }
}

While passing the receipt:

let expirationDate = expirationDateFromResponse(receipt)

@odedharth @Bizzi-Body That's correct. This method should be all you need:

SwiftyStoreKit.verifyReceipt(password: "your_shared_secret")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdforte picture rdforte  路  3Comments

iTarek picture iTarek  路  7Comments

anatoliykant picture anatoliykant  路  5Comments

jlaws picture jlaws  路  6Comments

andresmontelpare picture andresmontelpare  路  9Comments