Iaps Actually Validating the Receipt (Swift)

IAPs actually validating the receipt (Swift)

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)")
}

Validate receipts iOS

You don't have to use a server. You can validate it on the client if you want. Or you could completely forgo any validation if you wanted (not recommended).

The rejection you are getting is most likely because this time around, they used a test env to validate IAP.

Their documentation states

If you are doing receipt validation, be sure to verify your receipt
with the production URL (https://buy.itunes.apple.com/verifyReceipt)
first. This applies even in the case where your app is used in the
sandbox environment. App Review will review the production version of
your app in the sandbox. When your app processes the receipt, it must
be capable of detecting the 21007 receipt status code and sending the
receipt to the sandbox receipt validation server
(https://sandbox.itunes.apple.com/verifyReceipt). Once your app is
approved and running in the production environment, sending the
receipt to the production server first is the correct action.

Notice that they don't specify where the receipt validation is done.

What your code lacks is the fallback to the sandbox. Hence why they rejected you this time around.



Related Topics



Leave a reply



Submit