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)")
}
iOS 7 Local (on device) Receipt Validation and In-App Purchases Check
Alright so here is what worked for me, Apple approved the app last night after multiple rounds of review appeals and re-submissions spanning almost a month.
Do NOT try and refresh the receipt when the app launches and do not block the UI. What I was doing was not showing any UI on launch until a receipt was found, so when prompted for the iTunes password on launch pressing cancel would show the limited version of the app, entering a correct password would try and download a new receipt and act according to whether one was found.
So on launch if you find a receipt thats fine, if not do not try and refresh it.
DO however refresh it when the user presses the Restore Purchases option.
Hope this helps.
Related Topics
Swift 4 JSONdecoder Optional Variable
Linking Pages in Swift Playgrounds [Xcode]
Do Protocols Have an Effect on The Retain Count
Swiftui: Make Remaining Area of List Item Detect Clicks
How to Make UItabbar Image Rounded in Swift Programmatically
Swift Loaditem Closure Not Running
How to Draw an Image in an Nsopenglview with Swift
Accessing "Self" in Initializing Closure
Why Is My App Returning Hundreds of Errors That Say "Undefinedsymbol"
Swift: How to Catch Exception When Parsing a Numeric String
Non-Translucent UItabbar Creates Strange Grey Bar
Load a Spritekit Scene from Another Bundle
Swift Initialization Rule Confusion
Swift 4: How to Asynchronously Use Urlsessiondatatask But Have The Requests Be in a Timed Queue
Update UIapplicationshortcutitem from Extension
How to Provide Default Implementation of an Objective-C Protocol in a Swift Protocol Extension
Calculate Range of String from Word to End of String in Swift