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 · 8 comments
Open

Purchase sheet may fail to appear on iOS 18.2 #4611

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

Comments

@MarkVillacampa
Copy link
Member

MarkVillacampa commented Dec 19, 2024

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.

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

5 participants