You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, you can't things the way you're attempting it. I would suggest having storeHelper.start() in your @main App struct and then have checks for products being purchased or subscribed in the first view that's displayed.
For example, see SimplePurchaseView() in StoreHelperDemo (https://github.com/russell-archer/StoreHelperDemo). That view could be called directly from your App struct. SimplePurchaseView() shows how to check for a non-consumable product purchase but the same thing would work for a subscription. Something like this:
@main struct YourApp: App {
@StateObject var storeHelper = StoreHelper()
var body: some Scene {
WindowGroup {
YourFirstView().environmentObject(storeHelper)
.task { storeHelper.start() }
}
}
}
struct YourFirstView: View {
@EnvironmentObject var storeHelper: StoreHelper
@State var purchaseState: PurchaseState = .unknown
let productId = "com.rarcher.nonconsumable.flowers.large"
var body: some View {
VStack {
// Product details here...
if purchaseState == .purchased {
Text("This product has already been purchased").multilineTextAlignment(.center)
} else {
Text("This product is available for purchase").multilineTextAlignment(.center)
}
Spacer()
}
.padding()
.task {
let purchased = (try? await storeHelper.isPurchased(productId: productId)) ?? false
purchaseState = purchased ? .purchased : .unknown
}
}
}
I want show content or notice subscription on the App's first View, so I need check subscribed first.
but
storeHelper.start()
is a async function, so thestoreHelper.subscriptionProductIds
is empty, and can not check subscribed.The text was updated successfully, but these errors were encountered: