Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKPaymentQueue.defaultQueue().addPayment(payment) Crash when moving between VC Swift

The IAP is working, but when I move between views and come back to the IAP VC, the app crashes in SKPaymentQueue.defaultQueue().addPayment(payment) ERROR: EXC_BAD_ACCESS

like image 812
Tal Zion Avatar asked Dec 25 '15 00:12

Tal Zion


1 Answers

I found the solution, you need to clean the SKPaymentQueue in the viewWillDisappear

Update Swift 4.x

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    SKPaymentQueue.default().remove(self)
}

Swift 2.3

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated: animated)
    SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
}
like image 187
Tal Zion Avatar answered Nov 05 '22 16:11

Tal Zion