UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

In app purchase Storekit SwiftUI button grayed out after purchase is complete in iOS 17

Forums > SwiftUI

I'm testing In App Purchase for my iOS app using iOS 17 with SwiftUI.

After successfully making a purchase the buy button is grayed out. This way I cannot test the purchase again. I even deleted the app and reinstalled it, but the button is still grayed out, like shown in the picture below.

This is the code I'm using. How do I enable the purchase button again?

import SwiftUI
import StoreKit

struct InAppPurchaseDetailView: View {
    var item:InAppItems

    var body: some View {

        NavigationStack {

            VStack {
                ProductView(id: item.identifier) {
                    Image(iconName)
                        .resizable()
                             .aspectRatio(contentMode: .fit)
                             .frame(maxWidth: 120, maxHeight: 120)
                             .cornerRadius(10)
                }
                .productViewStyle(.large)
                .padding()
                .onInAppPurchaseStart { product in
                    print("User has started buying \(product.id)")
                }
                .onInAppPurchaseCompletion { product, result in
                    if case .success(.success(let transaction)) = result {
                        print("Purchased successfully: \(transaction.signedDate)")
                    } else {
                        print("Something else happened")
                    }
                }
            }
        }             
        .onAppear() {

        }
    }

}

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.