mirror of
https://github.com/jaywcjlove/StoreKitHelper
synced 2026-04-21 13:37:20 +00:00
perf: Optimize error alert handling.
This commit is contained in:
parent
99ab4f7338
commit
7f2a1db892
4 changed files with 15 additions and 31 deletions
|
|
@ -27,17 +27,12 @@ struct RestorePurchasesButton: View {
|
|||
Button(action: {
|
||||
Task {
|
||||
restoringPurchase = true
|
||||
do {
|
||||
try await store.restorePurchases()
|
||||
restoringPurchase = false
|
||||
if store.purchasedProductIDs.count > 0 {
|
||||
popupDismissHandle?()
|
||||
} else if showError(error: store.storeError) == true {
|
||||
NotifyAlert.alert(title: store.storeError?.description(locale: locale) ?? noPurchaseTitle, message: "")
|
||||
}
|
||||
} catch {
|
||||
restoringPurchase = false
|
||||
NotifyAlert.alert(title: restoreFailedTitle, message: error.localizedDescription)
|
||||
await store.restorePurchases()
|
||||
restoringPurchase = false
|
||||
if store.purchasedProductIDs.count > 0 {
|
||||
popupDismissHandle?()
|
||||
} else if showError(error: store.storeError) == true {
|
||||
NotifyAlert.alert(title: store.storeError?.description(locale: locale) ?? noPurchaseTitle, message: "")
|
||||
}
|
||||
}
|
||||
}, label: {
|
||||
|
|
|
|||
|
|
@ -110,8 +110,7 @@ public final class StoreContext: ObservableObject {
|
|||
|
||||
do {
|
||||
// 同步 App Store 状态
|
||||
let result = try await AppStore.sync()
|
||||
print("AppStore.sync:", result)
|
||||
try await AppStore.sync()
|
||||
// 更新购买状态
|
||||
await updatePurchasedProducts()
|
||||
|
||||
|
|
|
|||
|
|
@ -110,15 +110,10 @@ public struct StoreKitHelperSelectionView: View {
|
|||
let purchaseFailed = String.localizedString(key: "purchase_failed", locale: locale)
|
||||
Task {
|
||||
buyingProductID = product.id
|
||||
do {
|
||||
try await store.purchase(product)
|
||||
buyingProductID = nil
|
||||
if store.isPurchased(product.id) == true {
|
||||
popupDismissHandle?()
|
||||
}
|
||||
} catch {
|
||||
buyingProductID = nil
|
||||
NotifyAlert.alert(title: purchaseFailed, message: error.localizedDescription)
|
||||
await store.purchase(product)
|
||||
buyingProductID = nil
|
||||
if store.isPurchased(product.id) == true {
|
||||
popupDismissHandle?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,15 +84,10 @@ struct ProductsLoadList: View {
|
|||
let purchaseFailed = String.localizedString(key: "purchase_failed", locale: locale)
|
||||
Task {
|
||||
buyingProductID = product.id
|
||||
do {
|
||||
try await store.purchase(product)
|
||||
buyingProductID = nil
|
||||
if store.isPurchased(product.id) == true {
|
||||
popupDismissHandle?()
|
||||
}
|
||||
} catch {
|
||||
buyingProductID = nil
|
||||
NotifyAlert.alert(title: purchaseFailed, message: error.localizedDescription)
|
||||
await store.purchase(product)
|
||||
buyingProductID = nil
|
||||
if store.isPurchased(product.id) == true {
|
||||
popupDismissHandle?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue