Skip to content

Commit

Permalink
Moved SKPaymentQueue.presentCodeRedemptionSheet to `StoreKitWorkaro…
Browse files Browse the repository at this point in the history
…unds` (#1967)

NFC.

I'll be using this method from 2 different places, and it belongs here
with the other workarounds.
  • Loading branch information
NachoSoto authored Oct 10, 2022
1 parent b981e0f commit 9e4b329
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
12 changes: 2 additions & 10 deletions Sources/Purchasing/StoreKit1/PaymentQueueWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,9 @@ class PaymentQueueWrapper: NSObject {
@available(watchOS, unavailable)
@available(macCatalyst, unavailable)
func presentCodeRedemptionSheet() {
// Even though the docs in `SKPaymentQueue.presentCodeRedemptionSheet`
// say that it's available on Catalyst 14.0, there is a note:
// This function doesn’t affect Mac apps built with Mac Catalyst.
// It crashes when called both from Catalyst and also when running as "Designed for iPad".
if self.paymentQueue.responds(to: #selector(SKPaymentQueue.presentCodeRedemptionSheet)) {
Logger.debug(Strings.purchase.presenting_code_redemption_sheet)
self.paymentQueue.presentCodeRedemptionSheet()
} else {
Logger.appleError(Strings.purchase.unable_to_present_redemption_sheet)
}
self.paymentQueue.presentCodeRedemptionSheetIfAvailable()
}

}

extension PaymentQueueWrapper: SKPaymentQueueDelegate {
Expand Down
22 changes: 22 additions & 0 deletions Sources/Purchasing/StoreKitAbstractions/StoreKitWorkarounds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,25 @@ extension ReceiptFetcher {
}

}

extension SKPaymentQueue {

@available(iOS 14.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(macCatalyst, unavailable)
func presentCodeRedemptionSheetIfAvailable() {
// Even though the docs in `SKPaymentQueue.presentCodeRedemptionSheet`
// say that it's available on Catalyst 14.0, there is a note:
// This function doesn’t affect Mac apps built with Mac Catalyst.
// It crashes when called both from Catalyst and also when running as "Designed for iPad".
if self.responds(to: #selector(SKPaymentQueue.presentCodeRedemptionSheet)) {
Logger.debug(Strings.purchase.presenting_code_redemption_sheet)
self.presentCodeRedemptionSheet()
} else {
Logger.appleError(Strings.purchase.unable_to_present_redemption_sheet)
}
}

}

0 comments on commit 9e4b329

Please sign in to comment.