Do I need to implement in app purchases to check app store receipt?

552 Views Asked by At

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?

0

There are 0 best solutions below