diff --git a/README.md b/README.md index 8464e7a..841ed90 100755 --- a/README.md +++ b/README.md @@ -109,6 +109,20 @@ var body: some View { } ``` +The default purchase call remains unchanged: + +```swift +await store.purchase(product) +``` + +If you need StoreKit purchase options, you can now pass them through directly: + +```swift +await store.purchase(product, options: [ + .appAccountToken(appAccountToken) +]) +``` + Compatible legacy usage: ```swift @@ -232,7 +246,7 @@ enum PurchaseStatus { ### StoreContext Methods -- `purchase(_ product: Product)` - Purchase a specific product +- `purchase(_ product: Product, options: Set = [])` - Purchase a specific product, optionally forwarding StoreKit purchase options - `restorePurchases()` - Restore previous purchases - `isPurchased(_ productID: ProductID) -> Bool` - Check if a product is purchased by ID - `isPurchased(_ product: InAppProduct) -> Bool` - Check if a product is purchased diff --git a/README.zh.md b/README.zh.md index 63fe63b..3b18808 100644 --- a/README.zh.md +++ b/README.zh.md @@ -109,6 +109,20 @@ var body: some View { } ``` +默认购买调用方式保持不变: + +```swift +await store.purchase(product) +``` + +如果需要传递 StoreKit 的购买选项,现在也可以直接透传: + +```swift +await store.purchase(product, options: [ + .appAccountToken(appAccountToken) +]) +``` + 兼容旧写法: ```swift @@ -230,7 +244,7 @@ enum PurchaseStatus { ### StoreContext 方法 -- `purchase(_ product: Product)` - 购买指定产品 +- `purchase(_ product: Product, options: Set = [])` - 购买指定产品,并可选透传 StoreKit 购买参数 - `restorePurchases()` - 恢复之前的购买 - `isPurchased(_ productID: ProductID) -> Bool` - 根据 ID 检查产品是否已购买 - `isPurchased(_ product: InAppProduct) -> Bool` - 检查产品是否已购买 diff --git a/Sources/StoreKitHelper/StoreKitHelper.swift b/Sources/StoreKitHelper/StoreKitHelper.swift index 698e17f..8429a60 100644 --- a/Sources/StoreKitHelper/StoreKitHelper.swift +++ b/Sources/StoreKitHelper/StoreKitHelper.swift @@ -92,10 +92,9 @@ public final class StoreContext: ObservableObject { // MARK: 购买产品 /// - Parameter product: 要购买的产品 - public func purchase(_ product: Product) async { + public func purchase(_ product: Product, options: Set = []) async { do { - let result = try await product.purchase() - + let result = try await product.purchase(options: options) switch result { case .success(let verificationResult): if let transaction = checkVerified(verificationResult) {