I have been trying to implement receipt validation in my spritekit game. I have been following various tutorial and basically ended up with this code
enum Reques
Thats is where you return your receipt as JSON and can access it. ie
if parseJSON["status"] as? Int == 0 {
println("Sucessfully returned purchased receipt data")
}
Will tell you if you have successfully got the receipt because ["status"] 0
means its been returned ok
You can further query and use the receipt data to find and use items from the JSON response. Here you can print the latest receipt info
if let receiptInfo: NSArray = parseJSON["latest_receipt_info"] as? NSArray {
let lastReceipt = receiptInfo.lastObject as! NSDictionary
// Get last receipt
println("LAST RECEIPT INFORMATION \n",lastReceipt)
}
Now you have your json data to use
You can now query that data, in this example we are finding out when the subscription expires of an auto renew subscription form the JSOn response
// Format date
var formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
// Get Expiry date as NSDate
let subscriptionExpirationDate: NSDate = formatter.dateFromString(lastReceipt["expires_date"] as! String) as NSDate!
println("\n - DATE SUBSCRIPTION EXPIRES = \(subscriptionExpirationDate)")
Post the above code under
if let parseJSON = json {
println("Receipt \(parseJSON)")
}