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
410 stars 48 forks source link

请教下 Storekit2 如何处理 Sent when a user initiates an IAP buy from the App Store事件 #8

Closed Tonyhe666 closed 1 year ago

Tonyhe666 commented 2 years ago

// Sent when a user initiates an IAP buy from the App Store @available(iOS 11.0, *) optional func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool

在Storekit2中如何处理?

russell-archer commented 1 year ago

Apple allows you to promote in-app purchases for sale directly on the App Store. This allows users to purchase your products from the App Store itself, rather than from within your app.

The requirement for supporting this feature is that your app must include a class that implements SKPaymentTransactionObserver, and the paymentQueue(_:updatedTransactions:) and paymentQueue(_:shouldAddStorePayment:for:) delegate methods. If you don't include these requirements then you'll get an error when you attempt to submit the app to the App Store and you have existing IAP promotions.

However, StoreKit2 doesn't include any of these: they're old-style StoreKit1 things.

StoreHelper has a solution to this potentially messy situation. It includes a class that handles all the requirements and tells the StoreKit2-based code when a direct App Store purchase is made. See comments in the readme (Direct purchases of App Store Promotions).