Skip to content

Commit

Permalink
Fix runtime crash in SK2TransactionListener in iOS < 15
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Sep 14, 2023
1 parent 1072870 commit bb1d3d6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sources/Purchasing/StoreKit2/StoreKit2TransactionListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ 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: Any

var updates: AsyncStream<TransactionResult> {
// swiftlint:disable:next force_cast
get { return self._updates as! AsyncStream<TransactionResult> }
}

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

func set(delegate: StoreKit2TransactionListenerDelegate) {
Expand Down

0 comments on commit bb1d3d6

Please sign in to comment.