transactionReceipt for in-app purchase is deprecated in iOS 7. What can I replace it with?
You can get the receipt as the contents of the mainBundle's appStoreReceiptURL. You can find references: developer.apple.com
This is untested code, but off the top of my head, I'd say something along the lines of:
[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]]
should get you the same result that transactionReceipt used to return.
Deprecated TransactionReceipt
Replace with something like:
[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
Convert NSData
to NSString
after that.....
How to use AppStoreReceiptUrl to verify StoreKit transactions in Xamarin.iOS
I finally implemented this, not a big of a deal as first expected. I used the code per the example at http://www.hassang.com/ and then I use a fallback on SKPaymentTransaction.TransactionReceipt which I also need as I still support iOS 6.
Why is the Apple AppStore in-app receipt empty on iOS?
In production there will always be a receipt (even if the app is free), that can contain your additional purchase, in case you have bought something or restored from an already purchased item.
In test environment until you buy something the receipt is nil
, if you want to test a case close to production, you should first try a restore (now you will have a receipt) and do what you need.
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
How to Set Gradient Background Transparency on iOS Safari
How to Fix Crash When Tap to Select Row After Scrolling The Tableview
How to Add Pagination in UItableview.
Data Repeat in UItableview When Scrolling
How Has The Nsindexpath Initialization Changed in Swift3
iOS Where to Put Custom Cell Design? Awakefromnib or Cellforrowatindexpath
Uiviewrepresentable Automatic Size - Passing UIkit UIview Size to Swiftui
How to Make a Synchronous Request Using Alamofire
Mpvolumeview Does Not Show Route Button on Launch
How to Prevent Duplicates in Realmswift List
Bluetooth Didconnect or Didfailtoconnect Not Called Xcode 9.2 with iOS 11.1.2
How to Display Collectionviewcell in Center in Swift 4
Can't Write Non Current User Objects by Pfuser Currentuser
Draw Polyline Using Google Maps in Custom View with Swift 3
How to Set Requestserializer in Alamofire