Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get details out of the latest receipt? #10

Closed
ghost opened this issue Jan 27, 2016 · 3 comments
Closed

How to get details out of the latest receipt? #10

ghost opened this issue Jan 27, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 27, 2016

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.

@phimage
Copy link
Contributor

phimage commented Jan 28, 2016

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

@odedharth
Copy link
Contributor

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)

@bizz84
Copy link
Owner

bizz84 commented Jul 10, 2016

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

SwiftyStoreKit.verifyReceipt(password: "your_shared_secret")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants