Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime crash in SK2TransactionListener in iOS < 15 #3206

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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