提问人:Mustafa Alper Alper 提问时间:11/9/2023 更新时间:11/9/2023 访问量:42
崩溃并显示“暂停 StoreKitManaer.purchase(_:) 的恢复部分功能”
Crash with "suspend resume partial function for StoreKitManaer.purchase(_:)"
问:
模拟器和真实设备测试中没有崩溃,在应用程序发布阶段我没有收到任何负面反馈。后来,当我从市场上下载已发布的应用程序并进行应用内购买时,我的应用程序崩溃了。Crashlytics 输出如下;<compiler-generated> - Line 4308224304 (5) suspend resume partial function for StoreKitManaer.purchase(_:) + 4308224304
我写的代码如下
VStack {
ScrollView {
ForEach(self.products) { product in
Button {
_ = Task<Void, Never> {
do {
try await self.purchase(product)
} catch {
print(error)
}
}
} label: {
VStack {
HStack {
if product.displayName.contains("50") {
Text(appState.langType == 1 ? "50 BKP" : "50 WAIP")
.font(.system(size: 20, weight: .semibold))
} else if product.displayName.contains("200") {
Text(appState.langType == 1 ? "200 BKP" : "200 WAIP")
.font(.system(size: 20, weight: .semibold))
} else {
Text("---")
.font(.system(size: 20, weight: .semibold))
}
Spacer()
Text(product.displayPrice)
.font(.system(size: 20, weight: .semibold))
}
}
}
}
}
}.task {
do {
try await self.loadProducts()
} catch {
print(error)
}
}
购买功能
private func loadProducts() async throws {
// Products are not returned in the order the ids are requested
self.products = try await Product.products(for: productIds)
}
private func purchase(_ product: Product) async throws {
let result: Product.PurchaseResult = try await product.purchase()
switch result {
case let .success(.verified(transaction)):
// Successful purchase
self.isPurchase = true
self.isPurchasePoint = Int(product.displayName)
var totalCoins = preferences.integer(forKey: "currrent_waip")
var newTotalCoins = totalCoins + Int(product.displayName)!
preferences.set(newTotalCoins, forKey: "currrent_waip")
await transaction.finish()
case let .success(.unverified(_, error)):
// Successful purchase but transaction/receipt can't be verified
// Could be a jailbroken phone
break
case .pending:
// Transaction waiting on SCA (Strong Customer Authentication) or
// approval from Ask to Buy
break
case .userCancelled:
// ^^^
break
@unknown default:
break
}
}
答: 暂无答案
评论