Skip to content

Commit 1b18e2c

Browse files
committed
fix(capacitor-ios): guard AppTransaction.shared with #available(iOS 16.0)
AppTransaction is only available from iOS 16.0 but refreshReceipts was not wrapped in an availability check, causing build failure when the deployment target is 15.0.
1 parent 7390535 commit 1b18e2c

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

capacitor/ios/Sources/PurchasePlugin/PurchasePlugin.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,23 @@ public class PurchasePlugin: CAPPlugin, CAPBridgedPlugin {
241241

242242
@objc func refreshReceipts(_ call: CAPPluginCall) {
243243
Task {
244-
do {
245-
let appTransaction = try await AppTransaction.shared
246-
switch appTransaction {
247-
case .verified(let transaction):
248-
call.resolve(["receipt": [
249-
"bundleIdentifier": transaction.bundleID,
250-
"appVersion": transaction.appVersion,
251-
]])
252-
case .unverified(_, _):
253-
call.reject("App transaction verification failed")
244+
if #available(iOS 16.0, *) {
245+
do {
246+
let appTransaction = try await AppTransaction.shared
247+
switch appTransaction {
248+
case .verified(let transaction):
249+
call.resolve(["receipt": [
250+
"bundleIdentifier": transaction.bundleID,
251+
"appVersion": transaction.appVersion,
252+
]])
253+
case .unverified(_, _):
254+
call.reject("App transaction verification failed")
255+
}
256+
} catch {
257+
call.reject("Failed to refresh receipts: \(error.localizedDescription)")
254258
}
255-
} catch {
256-
call.reject("Failed to refresh receipts: \(error.localizedDescription)")
259+
} else {
260+
call.reject("refreshReceipts requires iOS 16.0 or newer")
257261
}
258262
}
259263
}

0 commit comments

Comments
 (0)