Крашлитикс отловил краши, не знаю пока как в них разбираться, помогите пожалуйста. Что-то, очевидно, связанное с покупками.
Первый crash. 15 строка апделегата, но там
class AppDelegate: UIResponder, UIApplicationDelegate
:#0 Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x003a746e7b8c78680 libobjc.A.dylib objc_msgSend + 28
1 StoreKit __NotifyObserverAboutChanges + 84
2 CoreFoundation CFArrayApplyFunction + 68
3 StoreKit -[SKPaymentQueue
_notifyObserversAboutChanges:sendUpdatedDownloads:] + 14815 UIKit UIApplicationMain + 208
16 Back AppDelegate.swift line 15main
17 libdispatch.dylib
(Missing)Второй crash, тоже 15 строка:
#0 Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000b002004500 libobjc.A.dylib objc_msgSend + 16
1 StoreKit __34-[SKProductsRequest _handleReply:]_block_invoke + 52
2 libdispatch.dylib _dispatch_call_block_and_release + 24
10 UIKit UIApplicationMain + 208
11 Back AppDelegate.swift line 15 main
12 libdispatch.dylib
(Missing)Третьий crash:
#0 Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000000000100 libobjc.A.dylib objc_msgSend + 16
4 StoreKit -[SKPaymentQueue addPayment:] + 316
5 Back ViewController.swift line 151
ViewController.buyProduct() -> ()6 Back ViewController.swift line 0
specialized ViewController.buyAllButtonTapped(UIButton) -> ()7 Back ViewController.swift line 0
@objc ViewController.buyAllButtonTapped(UIButton) -> ()8 UIKit -[UIApplication sendAction:to:from:forEvent:] + 96
23 UIKit UIApplicationMain + 208
24 Back AppDelegate.swift line 15 main
25 libdispatch.dylib
(Missing)
Код покупок:
// Проверка на возможность покупки
if SKPaymentQueue.canMakePayments() {
print("Покупки доступны")
let productID: Set<String> = ["Back.BuyAllThings"]
let request = SKProductsRequest(productIdentifiers: productID)
request.delegate = self
request.start()
}
else {
print("Покупки не доступны")
}
// Добавляем платеж в очередь платежей
func buyProduct() {
print("buy " + productToPurchase.productIdentifier)
let pay = SKPayment(product: productToPurchase)
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().add(pay)
} // 151 LINE
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
print("Product request phase")
let myProduct = response.products
for product in myProduct {
print("Товар добавлен")
print("Идентификатор продукта: \(product.productIdentifier)")
print("\(product.localizedTitle)")
print("\(product.localizedDescription)")
listOfProducts.append(product)
}
}
//НАЖАТИЕ НА КНОПКУ ПОКУПКИ
func buyAllButtonTapped(_ sender:UIButton) {
print("КУПИЛ ВСЕ ПОКУПКИ")
for product in listOfProducts {
let productID = product.productIdentifier
if productID == "ru.artursk.Back.BuyAllThings" {
productToPurchase = product
buyProduct()
break
}
}
/ Обновляет сведения о транзакции
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
print("Ошибка: \(transaction.error)")
switch transaction.transactionState {
case .purchased:
print("Оплата прошла успешно")
print(productToPurchase.productIdentifier)
let prodID = productToPurchase.productIdentifier
switch prodID {
case "Back.BuyAllThings":
print("Покупаем All Things")
addAll() // АКТИВИРУЕМ КУПЛЕННОЕ
break
default:
break
}
queue.finishTransaction(transaction)
break
case .failed:
print("Ошибка транзакции")
queue.finishTransaction(transaction)
default:
print("paymentQuene - default case")
break
}
}
}
func paymentQueue(_ queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
print("удаляем транзакцию из очереди")
}
4 StoreKit -[SKPaymentQueue addPayment:] + 316
- строка с номером 316), было бы неплохо, если бы вы в коде где то дали указание, типа вот строка 316remove(self)
.