Skip to content

Commit

Permalink
Fix runtime crash in SK2TransactionListener in iOS < 15 (#3206)
Browse files Browse the repository at this point in the history
### Description
We found that there was another runtime crash in Capacitor in iOS < 15
similar to #3139. This
applies the same fix to this new crash.
  • Loading branch information
tonidero authored Sep 14, 2023
1 parent 1072870 commit e100bd3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/Purchasing/StoreKit2/StoreKit2TransactionListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ actor StoreKit2TransactionListener: StoreKit2TransactionListenerType {
private(set) var taskHandle: Task<Void, Never>?

private weak var delegate: StoreKit2TransactionListenerDelegate?
private let updates: AsyncStream<TransactionResult>

// We can't directly store instances of `AsyncStream`, since that causes runtime crashes when
// loading this type in iOS <= 15, even with @available checks correctly in place.
// See https://openradar.appspot.com/radar?id=4970535809187840 / https://github.com/apple/swift/issues/58099
private let _updates: Box<AsyncStream<TransactionResult>>

var updates: AsyncStream<TransactionResult> {
return self._updates.value
}

init(delegate: StoreKit2TransactionListenerDelegate? = nil) {
self.init(delegate: delegate, updates: StoreKit.Transaction.updates)
Expand All @@ -71,7 +79,7 @@ actor StoreKit2TransactionListener: StoreKit2TransactionListenerType {
updates: S
) where S.Element == TransactionResult {
self.delegate = delegate
self.updates = updates.toAsyncStream()
self._updates = .init(updates.toAsyncStream())
}

func set(delegate: StoreKit2TransactionListenerDelegate) {
Expand Down

0 comments on commit e100bd3

Please sign in to comment.