0

For a free app– yet to be published on the Apple App Store, I am struggling to test out the receipt validation feature.

Bundle.main.appStoreReceiptURL is where the receipt is apparently located but offers no guarantee of there is a file at the end of it.

My assumption is:

  1. Once an app is downloaded from the App Store, there must be a receipt. Even if the app is free
  2. This receipt is verifiable through: https://developer.apple.com/documentation/appstorereceipts/responsebody/receipt
  3. An In-App Purchase is not necessarily needed to create that receipt.

Are the above assumptions accurate? If so, cannot find a way to look at even a sample receipt (even when downloaded on TestFlight).

I'm not sure how to test this!

extension DebugViewController: SKRequestDelegate {
    
    
    func checkReceipt() {
        
        let msg: String
        let url = Bundle.main.appStoreReceiptURL!
        if FileManager.default.fileExists(atPath: url.path) {
            if let data = try? Data(contentsOf: url) {
                msg = data.description
                print(msg)
                let t = TextViewController(msg)
                show(t, sender: nil)
            }
        }
        else {
            msg = "No file Found at the url, requesting from appstore...\n\n\(url.absoluteString)"
            let request = SKReceiptRefreshRequest(receiptProperties: nil)
            request.delegate = self
            self.request = request
            self.request?.start()
        }
    }
    
        
    func requestDidFinish(_ request: SKRequest) {
        
        showMsg("completed request", "completed")
        
        var msg: String = "Starting.."
        let url = Bundle.main.appStoreReceiptURL!
        if FileManager.default.fileExists(atPath: url.path) {
            if let data = try? Data(contentsOf: url) {
                msg = data.description
                print(msg)
                let t = TextViewController(msg)
                show(t, sender: nil)
            }
        }
        else {
            msg = "No file exists at path \(url.absoluteString) despite refreshing"
            let t = TextViewController(msg)
            show(t, sender: nil)
        }
        
    
    }
    
    func request(_ request: SKRequest, didFailWithError error: Error) {
        
        let errorStr = String(describing: error)
        let t = TextViewController(errorStr)
        show(t, sender: nil)
    }
}

user134611
  • 766
  • 1
  • 11
  • 22

0 Answers0