Reputation: 3233
I am getting a crash with the following error message:
[FilterPurchase respondsToSelector:]: message sent to deallocated instance 0x1edacba0
This occurs on this line:
[[SKPaymentQueue defaultQueue] addPayment:payment];
The problem occurs when I load the In App Purchase View, then remove the view from superview and then re-open it and click to make a purchase.
Has anyone got any ideas on how I could correct this issue. Don't know if the above is enough information to correct the issue.
Don't know if this has anything to do with it but it is called on each load.
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
Thanks
Upvotes: 3
Views: 2814
Reputation: 1213
You need to clean the SKPaymentQueue in the viewWillDisappear
Swift 2.2
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(true)
SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
}
Swift 2.3
override func viewWillDisappear(animated: Bool) {
SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
}
Swift 3.0
override func viewWillDisappear(_ animated: Bool) {
SKPaymentQueue.default().remove(self)
}
Upvotes: 0
Reputation: 12677
One of reasons of the crash can be insertion of SKPayment with empty productIdentifier
.
Upvotes: 0
Reputation: 3233
The problem I think is fixed. Just before the back button to close the modal is pressed I call.
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
Upvotes: 8