5

I am implementing in-app purchases in a Swift 3.0 app so I need to grab the app receipt to verify it against the iTunes store. Here is how I am getting the receipt:

func getReceipt() -> Data? {
    if Bundle.main.appStoreReceiptURL != nil {
        print("app receipt: \(Bundle.main.appStoreReceiptURL)")
        do {
            let receiptData = try Data(contentsOf: Bundle.main.appStoreReceiptURL!)
            print(receiptData)
            return receiptData
        } catch {
            print("error converting receipt to Data: \(error.localizedDescription)")
        }
    }
    return nil
}

my console output for the receipt URL is:

app receipt: Optional(file:///Users/dustinspengler/Library/Developer/XCPGDevices/433E8E8F-B781-4ADC-A92D-5CABC28E94D6/data/Containers/Data/Application/C25BE9B6-FB64-4D49-9CF2-9DA371060A7B/StoreKit/receipt)

It then failed to convert the receipt to Data and the catch statement prints:

error converting receipt to Data: The file “receipt” couldn’t be opened because there is no such file.

I get the exact same output when running this in a playground, simulator, and real devices so does this mean that no receipt exists for the app considering the fact that the user has not made an in-app purchase yet? When reading through Apple's documentation I got the impression that they are always created created regardless of prior purchases.

Dustin Spengler
  • 5,478
  • 4
  • 28
  • 36
  • 1
    There is no receipt until the user makes *a purchase*. For an app downloaded from the App Store (even a free one). This is *a purchase*, so there will be a receipt. For a debug build from Xcode there is no receipt until an in-app purchase is made. – Paulw11 Mar 31 '17 at 20:23
  • Thanks for the response @Paulw11! If you want to submit this as an answer I will accept it. – Dustin Spengler Mar 31 '17 at 23:09
  • considering this info is not listed in Apples documentation, does anyone care to comment on the down down vote? – Dustin Spengler Apr 04 '17 at 15:13

1 Answers1

7

This answer is based off the context that the app is being run on your local machine. If the app is live in the app store, a receipt will be in place the moment you download the app even if its free.

Answered by @Paulw11:

There is no receipt until the user makes a purchase. For an app downloaded from the App Store (even a free one). This is a purchase, so there will be a receipt. For a debug build from Xcode there is no receipt until an in-app purchase is made.

Dustin Spengler
  • 5,478
  • 4
  • 28
  • 36
  • Not sure if this has changed, but I am running iOS 12 and Xcode 10, build from Xcode to my device and was able to get a receipt after calling SKReceiptRefreshRequest. After that Bundle.main.appStoreReceiptURL contained a receipt. – Augie Dec 07 '18 at 18:19
  • This information is incorrect. As soon as the user downloads an app from the app store, even a free one, there is a receipt, the app's receipt that corresponds to the app's purchase itself. If the app has in-app purchases or subscriptions, then the receipt will contain these purchases too. – Duck Jan 05 '20 at 09:12
  • What about TestFlight builds? – diachedelic Jan 06 '23 at 23:05
  • @diachedelic I am not sure about test flight apps. I would imagine since they weren't downloaded from the app store they wont have a receipt but I have not tested. – Dustin Spengler Jan 07 '23 at 15:26
  • They appear not to have a receipt, I was just wondering if it was documented anywhere. – diachedelic Jan 07 '23 at 22:14