Search code examples
iosswiftmacosin-app-purchasemac-catalyst

Mac Catalyst error: Cannot override 'paymentQueue' which has been marked unavailable


I have an iOS app in Swift that implements the paymentQueue(_:shouldAddStorePayment:for:) method in SKPaymentTransactionObserver. When I am porting this app to Mac using Mac Catalyst, however, whenever I try to compile and run it on Mac it gives me this compile error which says "Cannot override 'paymentQueue' which has been marked unavailable".

I tried adding #if os(iOS) ... #endif and @available(iOS 11, *) statements around the paymentQueue method but it still gives me this error.

Here is the error-ridden code currently:

#if os(iOS)
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {
    return true
}
#endif

Anyone else encountering this problem?


Solution

  • You can prevent code from being compiled into a Mac Catalyst build with the !targetEnvironment(macCatalyst) condition:

    #if !targetEnvironment(macCatalyst)
    func paymentQueue(_ queue: SKPaymentQueue,
                      shouldAddStorePayment payment: SKPayment,
                      for product: SKProduct) -> Bool {
        return true
    }
    #endif