Я делаю игру в Sprite Kit.
У меня есть файл IAPProducts Swift с кодом:
import Foundation
enum IAPProducts: String {
case nonConsumable1 = "Kingdom.Lion"
case nonConsumable2 = "Kingdom.Sheep"
}
и файл IAPService.Swift с кодом:
import Foundation
import StoreKit
var lionpurchased = false
var sheeppurchased = false
class IAPService: NSObject {
private override init() {}
static let shared = IAPService()
var products = [SKProduct]()
let paymentQueue = SKPaymentQueue.default()
func getProducts() {
let products: Set = [
IAPProducts.nonConsumable1.rawValue,
IAPProducts.nonConsumable2.rawValue
]
let request = SKProductsRequest(productIdentifiers: products)
request.delegate = self
request.start()
paymentQueue.add(self)
}
func purchase(product: IAPProducts) {
guard let productToPurchase = products.filter({ $0.productIdentifier == product.rawValue }).first else { return }
let payment = SKPayment(product: productToPurchase)
paymentQueue.add(payment)
}
func restorePurchases() {
print("restore purchases")
paymentQueue.restoreCompletedTransactions()
}
}
extension IAPService: SKProductsRequestDelegate {
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
products = response.products
for product in response.products {
print(product.localizedTitle)
}
}
}
extension IAPService: SKPaymentTransactionObserver {
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
print(transaction.transactionState.status(), transaction.payment.productIdentifier)
switch transaction.transactionState {
case .purchasing: break
default: queue.finishTransaction(transaction)
}
}
}
}
extension SKPaymentTransactionState {
func status() -> String {
switch self {
case .deferred: return "deferred"
case .failed: return "failed"
case .purchased:
return "purchased"
case .purchasing: return "purchasing"
case .restored: return "restored"
}
}
}
Проблема заключается в том, что мне нужно знать, какой не совместимый продуктБыл куплен?Мне нужно знать, что я должен проверить равен IAPProducts.nonConsumable1.rawValue и IAPProducts.nonConsumable2.rawValue