saturngod / IAPHelper

No more maintenance for this repo. Please use the https://github.com/bizz84/SwiftyStoreKit
MIT License
1.55k stars 280 forks source link

Need to removeTransactionObserver #9

Closed hughlang closed 8 years ago

hughlang commented 10 years ago

I was having a problem where I would occasionally get the following error while trying to restore products. (only if NSZombieEnabled)

[IAPHelper respondsToSelector:]: message sent to deallocated instance 0x17668730

I found that I had to add this somewhere in the IAPHelper.m code:

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

I chose to put it in a dealloc method, though there might be better places for this. It did fix my problem though.

See also: http://stackoverflow.com/questions/4150926/in-app-purchase-crashes-on-skpaymentqueue-defaultqueue-addpaymentpayment

brandonscript commented 9 years ago

@saturngod do you agree this is the appropriate place to put this?

mohammad19991 commented 9 years ago

adding [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; in dealloc didn't work for me and the app still crashing on iOS 7

saturngod commented 9 years ago

@mohammad19991 , sorry about that. I will test now and let know you after that.

mohammad19991 commented 9 years ago

@saturngod No worries, look I didn't know what's the problem but something is getting deallocated from the memory and the crash only happens on iOS 7 and I couldn't find it so I rolled back last commit in my code and it's working better now but the crash still happening a little.

saturngod commented 9 years ago

@mohammad19991 , may I know are you using [IAPShare sharedHelper].iap or you just allocate your own object like

IAPHelper *iap = [[IAPHelper alloc] initWithProductIdentifiers:dataSet]

Look like it already dealloc the IAPHelper but transaction is not finish yet

May I know , how did you allocate the object.

Or , did you dealloc the iap like

[IAPShare sharedHelper].iap = nil;

If it's , may I know where did you put

mohammad19991 commented 9 years ago

I alloc the object like below:

[IAPShare sharedHelper].iap = [[IAPHelper alloc] initWithProductIdentifiers:Identifiers];

and I don't use [IAPShare sharedHelper].iap = nil; to dealloc the objects