Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing In-App Purchases with SwiftUI [closed]

I am trying to implement InAppPurchases into SwiftUI application.

None of what I found worked fine for me.

As I understand all IAP guides for UIKit do not work with SwiftUI as they are based on UIView delegates which would not work with SwiftUI.

So in SwiftUI, how would you connect the user input to the purchase/restore functions, etc?

like image 501
Hekes Pekes Avatar asked Dec 04 '25 21:12

Hekes Pekes


1 Answers

While I don't have a guide, I do have some suggestions.

As I work with SwiftUI, I'm finding that it really enforces separation of UI from app logic. In the past, it was easy to muddle the two together in UIViews and UIViewControllers. Now, you have to clearly separate it out.

So I would suggest the following:

  • Use those guides to build backend support for In-App Purchases. Build your managing class/controller that handles the actual logic of making the request, checking for purchases, etc. But don't implement any UI.
  • In that class, add support for purchasing your IAP.
  • Have a Button whose action calls your manager's function to purchase your IAP.

It should provide simple functionality for you. If you care about having an activity spinner or something like that, then you can implement those later. But otherwise, this should get you started.

like image 110
Josh Hrach Avatar answered Dec 07 '25 14:12

Josh Hrach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!