0

I'm want to turn my paid iOS app to a free one. I want the paid users to have all the features they paid for, and the free users will get other features.

All the tutorials for app validation are very complicated for me and seem to involve IAP.

I simply just want to check the original download version of the App, (not IAP) & the original purchase date if possible and parse that so I can setup the app correctly.

My code is acting as if a receipt does not exist when I run on simulator or on device, I'm not sure how ot get a receipt so I can test this, do I need to set up an IAP in order to get the initial receipt? Have been stuck at this for days so any help would be aprecieated!

Here is my code for validating the receipt which I learned from a tutorial, it returns nothing:

func validateReceipt() {

        #if DEBUG

                   let urlString = "https://sandbox.itunes.apple.com/verifyReceipt"

               #else

                   let urlString = "https://buy.itunes.apple.com/verifyReceipt"

               #endif

        guard let receiptURL = Bundle.main.appStoreReceiptURL, let receiptString = try? Data(contentsOf: receiptURL).base64EncodedString() , let url = URL(string: urlString) else {

                return

            }

        let requestData : [String : Any] = ["receipt-data" : receiptString,

                                            "password" : sharedSecret,

                                            "exclude-old-transactions" : false]

        let httpBody = try? JSONSerialization.data(withJSONObject: requestData, options: [])

        var request = URLRequest(url: url)

        request.httpMethod = "POST"

        request.setValue("Application/json", forHTTPHeaderField: "Content-Type")

        request.httpBody = httpBody

        URLSession.shared.dataTask(with: request)  { (data, response, error) in

            // convert data to Dictionary and view purchases
            DispatchQueue.main.async {

                if let data = data, let jsonData = try? JSONSerialization.jsonObject(with: data, options: .allowFragments){

                // your non-consumable and non-renewing subscription receipts are in `in_app` array
                    
                    print("JSON Data: ", jsonData)

                // your auto-renewable subscription receipts are in `latest_receipt_info` array

                }

            }

        }.resume()
    
    }

How can I get a receipt and check the original purchase date/version so I can honor the paid app users and change this into a free app?

Peter Ruppert
  • 1,067
  • 9
  • 24
  • https://developer.apple.com/documentation/storekit/original_api_for_in-app_purchase/validating_receipts_with_the_app_store – lorem ipsum May 15 '22 at 12:24
  • 1
    @loremipsum I tried following that but `if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL, FileManager.default.fileExists(atPath: appStoreReceiptURL.path)` doesn't happen. The files seems to not exist. – Peter Ruppert May 15 '22 at 13:26
  • I pasted the link for the big red box in it. Apple does not want you to verify receipts on device like this. You should look at the documentation. There are also many tutorials on how to read receipts on device. It isn't an answer just an observation. – lorem ipsum May 15 '22 at 13:38
  • 1
    @loremipsum I see, atm I am just trying to test to see if I can even get a receipt and set up how am I going to parse it etc, when that was figured out I was going to figure the next step do via a server as they suggested. I even previously set up that way, but it seems no receipt exists to send for verification – Peter Ruppert May 15 '22 at 14:56
  • You would probably be better off trying StoreKit 2. A lot of the "difficult" coding is done. There is a WWDC 21 video on it. – lorem ipsum May 15 '22 at 16:42

0 Answers0