russell-archer / StoreHelper

Implementing In-App Purchases with StoreKit2 in Xcode 13 - 15 using SwiftUI, Swift 5.7 - 5.9, iOS 15 - 17 and macOS 12 - 14. Also supports tvOS and visionOS.
MIT License
422 stars 52 forks source link

Xcode Reports missing update task? #35

Closed drallgood closed 1 year ago

drallgood commented 1 year ago

Xcode is reporting this warning at runtime (in Debug mode): Sources/StoreHelper/Core/StoreHelper.swift:361 Making a purchase without listening for transaction updates risks missing successful purchases. Create a Task to iterate Transaction.updates at launch.

russell-archer commented 1 year ago

I can't reproduce this in Xcode 14.2.

StoreHelper starts listening for transactions as soon as you call storeHelper.start():

@available(iOS 15.0, macOS 12.0, *)
@main
struct StoreHelperDemoApp: App {
    @StateObject var storeHelper = StoreHelper()

    var body: some Scene {
        WindowGroup {
            MainView()
                .environmentObject(storeHelper)
                .task { storeHelper.start() } // Start listening for transactions
        }
    }
}

@available(iOS 15.0, macOS 12.0, *)
public class StoreHelper: ObservableObject {
    :
    :
    /// Call this method as soon as possible after your app starts and StoreHelper has been initialized.
    /// Failure to call` start()` may result in transactions being missed.
    /// This method starts listening for App Store transactions and requests localized product info from the App Store.
    @MainActor public func start() {
        guard !hasStarted else { return }

        // Listen for App Store transactions
        transactionListener = handleTransactions()

        // Get localized product info from the App Store
        refreshProductsFromAppStore()
    }
}
drallgood commented 1 year ago

That's what I thought. It might just be a false positive produced by Xcode