Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftStoreKit.ReceiptError error 1 #392

Open
5 tasks
Tracked by #550
Yetispapa opened this issue Aug 2, 2018 · 32 comments
Open
5 tasks
Tracked by #550

SwiftStoreKit.ReceiptError error 1 #392

Yetispapa opened this issue Aug 2, 2018 · 32 comments

Comments

@Yetispapa
Copy link

Yetispapa commented Aug 2, 2018

Platform

  • [X ] iOS
  • macOS
  • tvOS

In app purchase type

  • Consumable
  • Non-consumable
  • [X ] Auto-Renewable Subscription
  • Non-Renewing Subscription

Environment

  • [ X] Sandbox
  • [X ] Production

Version

0.13.3

Report

Issue summary

We're fetching the receipt in order to validate if the subscription is still valid or not. In order to do so we fetch the receipt and sent the encoded receipt to our server. This is our code:

    SwiftyStoreKit.fetchReceipt(forceRefresh: false) { result in

        switch result {
        case .success(let receiptData):

            let encryptedReceipt = receiptData.base64EncodedString(options: [])

            Log.info("Fetch receipt success")

            //further code to send the receipt to our server

        case .error(let error):
            observer.send(error: error.localizedDescription)
        }
    }

Everything works on my side but unfortunately the Apple reviewer gets the error which is shown in the section below. So error.localizedDescription is the alert message. Now I looked through the errors from SwiftStoreKit and I'm a bit hopeless cause I couldn't find any error with code 1. Could someone help me here?

What did you expect to happen

Fetching receipt is successfull and the receipt will be send to our sever for validation without error

What happened instead

screen shot 2018-08-02 at 11 24 36

@0xTomTom
Copy link

Would like to know also.

@Starsky89
Copy link

This error appears when on a fresh install of the app with no receipt at all, you're trying to get that receipt, either from the iPhone or from the Apple servers, where there's no receipt as well, because you never bought anything. Make sure you handle this error.

@anta-semenov
Copy link

I also have this issue. But I have it when I fetch receipt after successful purchase.

@ab-zephyr
Copy link

Same here. Apple reviewer has such an error after successful subscription. What can be wrong?

@KasykhinAndrey
Copy link

this issue still exists in release 0.15.0

@KasykhinAndrey
Copy link

in my case I got this error when :

  • trying to get that receipt : SwiftyStoreKit.fetchReceipt
  • Alert appears with title: Sign In to iTunes Store and message: Enter the password for your Apple ID. Cancel button pressed.

result received :
FetchReceiptResult
▿ error : 1 element
▿ error : ReceiptError
▿ networkError : 1 element
- error : Error Domain=SSErrorDomain Code=16 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}

error.localizedDescription
"The operation couldn’t be completed. (SwiftyStoreKit.ReceiptError error 1.)"

@sameersyd
Copy link

sameersyd commented Jun 13, 2020

I too have this issue, occurs when I try to verify receipt. Although it's fine for Me, only apple reviewer gets this each time. Does someone know what could be wrong or is this related to submitting our subscription. In appStoreConnect, my subscription is still showing "waiting for review".

SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
...

@Sam-Spencer Sam-Spencer mentioned this issue Jun 23, 2020
9 tasks
@cclaflin89
Copy link

Same here in 0.16.0. Everything works fine on my device. But Apple rejected the build and sent the error screenshot.

@sameersyd
Copy link

Same here in 0.16.0. Everything works fine on my device. But Apple rejected the build and sent the error screenshot.

Do you know any alternative? Until these guys fix this?

@cclaflin89
Copy link

Not found alternative solution yet.

@sameersyd
Copy link

sameersyd commented Jul 7, 2020 via email

@tc976562936
Copy link

I have also encountered this problem, but have been unable to find a solution, I hope to get help, thank you!

@Isuru-Nanayakkara
Copy link

Isuru-Nanayakkara commented Jan 1, 2021

My app got rejected with the same error.


Update:

Something I noticed while reading this Apple document.

> Use the test environment URL https://sandbox.itunes.apple.com/verifyReceipt when testing your app in the sandbox and while your application is in review. Use the production URL https://buy.itunes.apple.com/verifyReceipt when your app is live in the App Store.

I wrote my code like this.

#if DEBUG
    AppleReceiptValidator(service: .sandbox, sharedSecret: secret)
#else
    AppleReceiptValidator(service: .production, sharedSecret: secret)
#endif

Since the app is technically a release build, it uses the production URL. But according to that article, while the app is in review, we should use the sandbox URL.

Could this be the issue?

If this is the case, we're at a dead-end when it comes to verifying receipts locally. Since there is no way to change the URLs within the app after the build is submitted, our only option is to go with the server-side validation, it seems.


Update 2:

Ignore my previous update. I found the real cause for the issue. See below.

@sameersyd
Copy link

sameersyd commented Jan 1, 2021

I have used a different library to verify receipt, and for other operations such as purchase, I've used SSK.

My app is live!

@Isuru-Nanayakkara
Copy link

I have used a different library to verify receipt, and for other operations such as purchase, I've used SSK.

My app is live!

Do you verify the receipts locally? What's the library you used?

@sameersyd
Copy link

sameersyd commented Jan 2, 2021

Do you verify the receipts locally? What's the library you used?

I've used TPInAppReceipt
Not a popular one, but works for now.

@Isuru-Nanayakkara
Copy link

Do you verify the receipts locally? What's the library you used?

I've used TPInAppReceipt
Not a popular one, but works for now.

Thanks :) btw I discovered something just now regarding this whilesifting through Apple docs. See my comment above. I updated it.

@sameersyd
Copy link

Thanks :) btw I discovered something just now regarding this whilesifting through Apple docs. See my comment above. I updated it.

Oh Cool! I've always given .production, will this "if else", fix it?

@Isuru-Nanayakkara
Copy link

Isuru-Nanayakkara commented Jan 2, 2021

Thanks :) btw I discovered something just now regarding this whilesifting through Apple docs. See my comment above. I updated it.

Oh Cool! I've always given .production, will this "if else", fix it?

No, my code is what's causing the issue, I think. The if block runs while I'm in development, the if else block runs when the app is released. The problem is Apple requires us to still call the sandbox URL while the app is in review. Even though the app is technically a release build so it calls the production URL. This might be what's giving the error.

@sameersyd
Copy link

No, my code is what's causing the issue, I think. The if block runs while I'm in development, the if else block runs when the app is released. The problem is Apple requires us to still call the sandbox URL while the app is in review. Even though the app is technically a release build so it calls the production URL. This might be what's giving the error.

Ahh ok. Then I would recommend if you wanna quick fix for now, you can use this TPInApp receipt. As this library does not require the URL, and takes itself. Btw after using this lib, my app has been accepted. I'll attach the code snippet below!

image

@Isuru-Nanayakkara
Copy link

No, my code is what's causing the issue, I think. The if block runs while I'm in development, the if else block runs when the app is released. The problem is Apple requires us to still call the sandbox URL while the app is in review. Even though the app is technically a release build so it calls the production URL. This might be what's giving the error.

Ahh ok. Then I would recommend if you wanna quick fix for now, you can use this TPInApp receipt. As this library does not require the URL, and takes itself. Btw after using this lib, my app has been accepted. I'll attach the code snippet below!

image

Thank you. I'll give this approach a try 👍🏼

@Isuru-Nanayakkara
Copy link

No, my code is what's causing the issue, I think. The if block runs while I'm in development, the if else block runs when the app is released. The problem is Apple requires us to still call the sandbox URL while the app is in review. Even though the app is technically a release build so it calls the production URL. This might be what's giving the error.

Ahh ok. Then I would recommend if you wanna quick fix for now, you can use this TPInApp receipt. As this library does not require the URL, and takes itself. Btw after using this lib, my app has been accepted. I'll attach the code snippet below!

By the way, is local receipt validation ideal for auto-renewable subscriptions? Because I need to get the latest data like the expiration date. Do I have to refresh the receipt at every launch to get the most updated one?

@sameersyd
Copy link

By the way, is local receipt validation ideal for auto-renewable subscriptions? Because I need to get the latest data like the expiration date. Do I have to refresh the receipt at every launch to get the most updated one?

Mine is a social media app, I refresh receipt before user uses a premium feature, every time. Not sure about your use-case, but should be fine.

@Isuru-Nanayakkara
Copy link

I got this issue fixed! @Starsky89 is correct. This error occurs when you're trying to refresh a receipt that does not exist. This seems to be the underlaying StoreKit error.

Screenshot 2021-01-06 at 8 48 01 AM

It doesn't tell much but upon further searching I came across this thread which confirmed the suspicion.

I changed my code to first check whether the receipt exist or not and then fire the verification code. My app got approved.

@sameersyd
Copy link

I got this issue fixed! @Starsky89 is correct. This error occurs when you're trying to refresh a receipt that does not exist. This seems to be the underlaying StoreKit error.

Screenshot 2021-01-06 at 8 48 01 AM

It doesn't tell much but upon further searching I came across this thread which confirmed the suspicion.

I changed my code to first check whether the receipt exist or not and then fire the verification code. My app got approved.

Great! Can you provide code snippet/SC of your function.

@Isuru-Nanayakkara
Copy link

I don't do anything special. I just run this check and handle things accordingly.

if SwiftyStoreKit.localReceiptData != nil {
    // Has a receipt. Verify it.
    let validator = AppleReceiptValidator(service: .production, sharedSecret: Constant.Secret.inAppPurchase)
    SwiftyStoreKit.verifyReceipt(using: validator) { result in
        switch result {
        case .success(let receipt):
            // handle success
        case .error(let error):
            // show error
        }
    }
} else {
    // There is no receipt.
    // Possibly a brand new user who has not purchased anything in the app before.
}

@blankdata
Copy link

The reviewers also rejected my app. In their test environment they get a "SwiftStoreKit.ReceiptError error 1" after restoring and verifying subscription purchases. In my sandbox environment, however, everything works fine.

So instead of receiving an empty receipt, they get no receipt and verification fails! (Thus, other approaches like InAppReceipt.refresh will also fail).

Isuru-Nanayakkara is right. You have to check if SwiftyStoreKit.localReceiptData is nil.

This information should be added to the wiki.

@Ajaay7
Copy link

Ajaay7 commented Dec 24, 2021

The App subscription works fine in the sandbox environment, but when apple reviewers test the app they got the below error after purchasing the subscription.

" The operation couldn't be completed.
(SwiftyStoreKit.ReceiptError error1.) "

only fetch recipt is used , I'm not using validate recipt anywhere in the code, but still I get the error.
Please can anyone help.

Code:-

   SwiftyStoreKit.fetchReceipt(forceRefresh: true) { result in
                switch result {
                  case .success(let receiptData):
                      let encryptedReceipt = receiptData.base64EncodedString(options: [])
                      // code to send recipt to backed server for verification and further process
                   case .error(let error):
                      print("Fetch receipt failed: \(error)")
                      AppDelegate.shared().window?.showToastAtMidBottom(message: (error as NSError).localizedDescription, time: 2.0)
                }
    }

@Ajaay7
Copy link

Ajaay7 commented Dec 24, 2021

@anta-semenov anta-semenov commented on 11 Jan 2019
I also have this issue. But I have it when I fetch receipt after successful purchase.

I also have this issue. But I have it when I fetch receipt after successful purchase.

hi Mr.anta-semenov did you find any solution

@artur-zaremba
Copy link

artur-zaremba commented Dec 29, 2021

I had the same issue when I sent app that worked in sandbox for review. Review team still had the error on its iPad. I had my own IAP manager which worked with StoreKit natively. After that I switched to SwiftyStoreKit with the hope that all common issues are fixed in the library. Seems that the error is pretty common and not obvious for devs.
I also use SwiftyStoreKit.fetchReceipt(forceRefresh: true) but according to the SwiftyStoreKit sources it works in the same way as @Isuru-Nanayakkara solution.
/// Return receipt data from the application bundle. This is read fromBundle.main.appStoreReceiptURL. public static var localReceiptData: Data? { return sharedInstance.receiptVerificator.appStoreReceiptData }

Code from receiptVerificator
var appStoreReceiptData: Data? { guard let receiptDataURL = appStoreReceiptURL, let data = try? Data(contentsOf: receiptDataURL) else { return nil } return data }
Does anybody have solution?

UPD: The problem is in accessing receipt at app's start on simulator after erasing its content and settings. I switched to TPInAppReceipt for receipt checks and the problem has gone.

@artur-zaremba
Copy link

Also I noticed that SwiftyStoreKit returns ReceiptError.noReceiptData in case there is no receipt data after fetchReceipt, but I can't remember that reviewers have faced that error.

@PurpleShrek
Copy link

PurpleShrek commented Apr 4, 2022

fetchReceipt

not work for me. Its work in sandbox, but users without subscriptions have problem in AppStore.

upd: If you check subscriptions during App started, you use bad solution. Read this #397 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests