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

Purchase sheet may fail to appear on iOS 18.2 #4611

Open
MarkVillacampa opened this issue Dec 19, 2024 · 23 comments
Open

Purchase sheet may fail to appear on iOS 18.2 #4611

MarkVillacampa opened this issue Dec 19, 2024 · 23 comments
Labels

Comments

@MarkVillacampa
Copy link
Member

MarkVillacampa commented Dec 19, 2024

UPDATE 2025/01/22: It seems iOS 18.3 RC fixes this issue and will be generally available very soon.

There's a bug introduced by Apple in iOS 18.2 which prevents the payment sheet from being displayed if the current scene's key window root view controller is not part of the view hierarchy.

When the issue manifests, there is a log error message printed in the console: Could not get confirmation scene ID for

This can happen if it is currently presenting a modal view controller with:

  • modalPresentationStyle = .fullScreen on UIKit
  • fullScreenCover(isPresented:onDismiss:content:) in SwiftUI

To workaround the issue:

  • Use modalPresentationStyle = .overFullScreen on UIKit
  • Use sheet(isPresented:onDismiss:content:) on SwiftUI

If your app manifests the issue but these workarounds do not apply to your view structure, make sure your root view controller is part of the view hierarchy when initiating a purchase.

We're working on a workaround so purchases continue to work for users of our SDK: #4610

Technical details

Apple added a new purchase method in iOS 18.2 which accepts a UIViewController, as well as a macOS 15.2 one that accepts an NSWindow.

https://developer.apple.com/documentation/storekit/product/purchase(confirmin:options:)-3bivf
https://developer.apple.com/documentation/storekit/product/purchase(confirmin:options:)-8eai6

All the purchase methods were reimplemented internally, and the old purchase(confirmIn:scene) and purchase(options:) methods end up calling the new purchase(confirmIn:viewController) method.

To select which UIViewController to pass as parameter, the algorithm roughly translates to:

UIApplication.shared.connectedScenes.filter { $0.activationState == .foregroundActive }?.keyWindow?.rootViewController

However, when you present a view controller with modalPresentationStyle = .fullScreen over the rootViewController the documentation says: The views belonging to the presenting view controller are removed after the presentation completes.

This is equivalent to doing:

// self is a UIViewController
self.view.removeFromSuperview()
try await product.purchase(confirmIn: self, options: [])

Which sure enough produces the dreaded Could not get confirmation scene ID for message.

@MarkVillacampa MarkVillacampa pinned this issue Dec 19, 2024
@RCGitBot
Copy link
Contributor

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

@inb4ohnoes
Copy link

inb4ohnoes commented Dec 19, 2024

Wanted to add, this issue manifests itself as a console log Could not find a UI anchor for xxx purchase.. I'm using RevenueCat in an iMessage app and I'm running into this issue.

image

@MarkVillacampa
Copy link
Member Author

Hi @inb4ohnoes,

Thanks for reporting this. Indeed it seems like StoreKit payments fail 100% of the time in App Extensions.

I've added a workaround specifically for App Extensions to the purchase-18.2 branch. Could you test it and let me know if it fixes the issue for you?

26c5a6a

@inb4ohnoes
Copy link

Thanks so much @MarkVillacampa, I'll try this as soon as I get home and report back!

@inb4ohnoes
Copy link

Ok just tried that branch and it seems to be working. I'll try to rush my build through review and see if customers are still seeing the issue. Thanks!

@Lakston
Copy link

Lakston commented Dec 23, 2024

Does anyonw knows if this bug could affect the react native package ?

@lukepighetti
Copy link

same question about flutter https://x.com/luke_pighetti/status/1871180719692886062

@MarkVillacampa
Copy link
Member Author

@Lakston @lukepighetti the short answer is "yes it could"

The bug is not specific to the RevenueCat SDK or the UI framework you're using, but to StoreKit, Apple's iOS framework for in-app purchases.

The best way to test if your app is affected is trying to make a purchase on an iOS 18.2 device or simulator. If the purchases sheet pops up that means your app is not affected.

@TomFluentjoy
Copy link

Hi, @MarkVillacampa . Could you please let me know when the bug fix will be released? We are encountering the same error and cannot determine the specific version related to this issue, as we are using the RevenueCat SDK, which depends on version 5.14.4.

@amucahidbozkurt
Copy link

Hi @MarkVillacampa ,
Our app was rejected because the App Store reviewer was unable to initiate the subscription.
Could you please let me know when the bug fix will be released?

Reviewer message:
We found that your in-app purchase products exhibited one or more bugs which create a poor user experience. Specifically, the app showed error product not available when we attempted to purchase subscriptions. Please review the details and resources below and complete the next steps.

Review device details:

  • Device type: iPad Air (5th generation)
  • OS version: iPadOS 18.2

@MarkVillacampa
Copy link
Member Author

Hello @amucahidbozkurt,

Are you able to reproduce the issue on your own device or simulator in the Sandbox environment, and specifically seeing the "Could not get confirmation scene ID for" message in the Console?

Asking because in the issue you mention "missing products" rather than not being able to purchase the products which is an issue thay is sometimes common when submitting an app for review whith newly created products.

@FurkanHanciSecond
Copy link

FurkanHanciSecond commented Jan 12, 2025

Same Here! i'm getting the issue, i think it is really certain cause my customers cannot purchase in my prod apps.
Screenshot 2025-01-12 at 4 54 48 PM

@astrokin
Copy link

astrokin commented Jan 13, 2025

I have 4 apps in production from the same source of code. they are different only in JSON files used as sources.
two of the apps fails with the same error (BOTH production!!! and sandbox)
failing apps is for BY (Belarus) and RU (Russia) regions
two others works fine:
they are for KZ (Kazakhstan) and UK (the Ukraine) regions.

Is it some kind of sanctions from Revenue cat? Guys please put attention on this @revenuecat-ops @RCGitBot @revenuecat-circleci-ios-certs @aboedo

this is so critical because people loosing money and customers

Unhandled error happened: Error Domain=RevenueCat.ErrorCode Code=2 "There was a problem with the App Store." UserInfo={NSLocalizedDescription=There was a problem with the App Store., NSUnderlyingError=0x301b43060 {Error Domain=StoreKit.StoreKitError Code=2 "Не удается выполнить запрос"}, readable_error_code=STORE_PROBLEM, source_file=RevenueCat/StoreKitError+Extensions.swift:43, source_function=asPurchasesError}

but the most crazies moment here is that the same builds works fine on other devices:
it fails on my iPhone 13 Pro with 18.2.1 but it works on my iPad Pro 18.3 (BOTH production!!! and sandbox)

@euroboy
Copy link

euroboy commented Jan 13, 2025

Same problem, sometimes I'm getting the error "There was a problem with the App Store.", but if payment sheet gets open - the free trial information is missing even if product has correctly set a free trial.

@MarkVillacampa
Copy link
Member Author

@FurkanHanciSecond sorry to hear you're hitting this issue. I'm hoping the recommendations from the issue details can help you track down the root cause of the bug in your app and potentially fix the issue.

@astrokin I believe your apps are experiencing this exact issue, but it's not relaxed to the country of origin. I was able to download your apps and reproduce the issue where the payment sheet does not pop up and I can see the message Could not get confirmation scene ID for using Console.app. I also recommend checking the instructions in the issue details which can help you track down the root cause of the bug in your app and potentially fix it.

@euroboy If payment sheet does not open sometimes, it can be because of this issue. Do you see the Could not get confirmation scene ID for message in the Xcode logs when that happens? The reason for the missing free trial information could be you're using an Apple Sandbox account that has already purchased before. If so I recommend creating a new Sandbox Account to test it.

To all three, if you're unable to track down the issue in your apps please write to me at mark (at) revenuecat.com and I will try to help you personally.

@astrokin
Copy link

@MarkVillacampa thank you for the answer and especially thank you for testing my app. Could you please explain how the console message Could not get confirmation scene ID for is related to the API error Unhandled error happened: Error Domain=RevenueCat.ErrorCode Code=2 "There was a problem with the App Store." UserInfo={NSLocalizedDescription=There was a problem with the App Store., NSUnderlyingError=0x301b43060 {Error Domain=StoreKit.StoreKitError Code=2 "Не удается выполнить запрос"}, readable_error_code=STORE_PROBLEM, source_file=RevenueCat/StoreKitError+Extensions.swift:43, source_function=asPurchasesError}

It would be great if you could give more details about the error and how to possibly fix it. As far as I understand it's not UI related issue. Sorry if I've missed something

@MarkVillacampa
Copy link
Member Author

Hi @astrokin, when the issue presents itself, StoreKit prints Could not get confirmation scene ID for to the console and then throws a StoreKitError.unknown error when the RevenueCat SDK calls StoreKit’s product.purchase() function. Our SDK catches this unknown error and then sends it back to your app’s code with the There was a problem with the App Store. error mentioned in your comment.

The underlying bug is actually UI related. StoreKit can't present the payment sheet because it cannot find a view to do it. This can happen when you're presenting a modal view controller with modalPresentationStyle = .fullScreen. There's more details in the issue description, in the first message of this thread.

@butterfly-valley
Copy link

Hi, React Native also seems to affected, at least in my testing on real device with iOs 18.2.1. Is there any workaround? I have tried both a modal and a separate screen/View to no avail, the subscription is processed correctly but when trying to return the purchase info StoreKit.StoreKitError is thrown.

@MarkVillacampa
Copy link
Member Author

@butterfly-valley Hi! You mention "the subscription is processed correctly", does this mean the purchase sheet with the price, etc opens up? If you can open the purchase sheet then this is a different issue.

@Toni77777
Copy link

I have the same issue:

Image

@butterfly-valley
Copy link

@butterfly-valley Hi! You mention "the subscription is processed correctly", does this mean the purchase sheet with the price, etc opens up? If you can open the purchase sheet then this is a different issue.

The subscription is processed correctly because it is active in the sandbox account. I can cancel it and purchase it again and again but there is no visual confirmation and this error is thrown.

@butterfly-valley
Copy link

@butterfly-valley Hi! You mention "the subscription is processed correctly", does this mean the purchase sheet with the price, etc opens up? If you can open the purchase sheet then this is a different issue.

It might have a user error from my side. I have implemented the workflow on Android, pushed the code and tested on iOs with no issues. Please accept my apologies.

@MarkVillacampa
Copy link
Member Author

@Toni77777 do you also see the Could not get confirmation scene ID for message? If not, you might be experiencing a different issue.

@butterfly-valley glad to know it's working for you now :)

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

No branches or pull requests