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
Building User Database Model in Firebase
Catch Objective-C Exception in Swift
Swiftui: Dismiss View Within MACos Navigationview
Proper Model for Multiple Alamofire Requests for Multiple Websites
Swiftui @Environmentobject Error: May Be Missing as an Ancestor of This View
Cannot Form Weak Reference to Instance of Class Nstextview
Swift: Deallocate Gamescene After Transition to New Scene
Convert Int to Uint32 in Swift
Swift Package Manager - Swift 4 Syntax
How to Override Layerclass in Swift
Wcsession Has Not Been Activated
Resetting Zone Allocator with Allocations Still Alive
How to Pass an Error Pointer in the Swift Language
How to Remove Quotes from String on Swift
How to Create a Hud on Top of My Scenekit.Scene