mirror of
https://github.com/jaywcjlove/StoreKitHelper
synced 2026-04-21 13:37:20 +00:00
feat: Add purchase options support
https://github.com/jaywcjlove/StoreKitHelper/issues/2
This commit is contained in:
parent
c4d0b81011
commit
9011f07769
3 changed files with 32 additions and 5 deletions
16
README.md
16
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<Product.PurchaseOption> = [])` - 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
|
||||
|
|
|
|||
16
README.zh.md
16
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<Product.PurchaseOption> = [])` - 购买指定产品,并可选透传 StoreKit 购买参数
|
||||
- `restorePurchases()` - 恢复之前的购买
|
||||
- `isPurchased(_ productID: ProductID) -> Bool` - 根据 ID 检查产品是否已购买
|
||||
- `isPurchased(_ product: InAppProduct) -> Bool` - 检查产品是否已购买
|
||||
|
|
|
|||
|
|
@ -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<Product.PurchaseOption> = []) 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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue