Purchase Intent does not work when app has been launched

I'm implementing PurchaseIntent.intents for App Store in-app purchase promotions, following Apple's WWDC guidance. The API only works on cold launch (killed→launch), but fails on background→foreground transitions, making App Store promotions unusable.

Sample code as followed from WWDC23 video "What's new in StoreKit 2 and StoreKit Testing in Xcode".

In the StoreKitManager observable class, I have this function which is initialized in a listening task:

func listenForPurchaseIntent() -> Task<Void, Error> {
        return Task { [weak self] in
            for await purchase in PurchaseIntent.intents {
                guard let self else { continue }
                let product = purchase.product
                
                await self.purchaseProduct(product)
            }
        }
    }

where purchaseProduct() will perform the call to:

try await product.purchase()

ISSUE: When the app is in background (after previously launched), and the purchase intent is initiated from Xcode Transaction Manager or using the "itms-services://?action=purchaseIntent" method, the system foregrounds my app but the purchase intent is never delivered to the waiting listener. The intent remains queued until the next cold launch (quit app and relaunch app). This could mean that if a user has installed the app, and has run the app, then tapped the promotional IAP from the App Store, the purchase intent will not show up until the next cold launch.

If the app is in quit state, then the system will foreground the app, and purchase intent is delivered correctly.

STEPS TO REPRODUCE

  1. Launch app (listener starts in StoreKitManager.init())
  2. Background app
  3. Add purchase intent via Xcode Transaction Manager
  4. Foreground app
  5. Result: No purchase sheet appears, no intent delivered

Workaround attempts: Using this either in a view or the main app:

func checkForPurchaseIntents() async {
        for await purchaseIntent in PurchaseIntent.intents {
            await storeKit.purchaseProduct(purchaseIntent.product)
        }
    }
  • Applied to .onChange(of: scenePhase) - Doesn't work, nothing happens.

  • Using UIApplication.willEnterForegroundNotification - Only works on the first time the app goes from background to foreground when purchase intent is sent. Doesn't work on second time or third time.

• Attempting to creating fresh listening task on each foreground - Does not work.

The question is:

How are we supposed to implement the PurchaseIntent API?

I have checked Apple sample projects like BackyardBirds, and sample projects from WWDC on StoreKit 2 but they never implemented Purchase Intent.

Purchase Intent does not work when app has been launched
 
 
Q