Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
Hi all,

After doing some survey related to In-App Purchase, I found that it is good practice if register SKPaymentQueue on launch to collect pending transactions. That is addTransactionObserver in didFinishLaunchingWithOptions method.

But I am thinking if I addTransactionObserver when app launch, where and when I have to remove transaction observer? If I didn't remove transaction observer, will the app get crash? So far I am addTransactionObserver when my store front is loaded (in viewDidLoad of my store front) and removeTransactionObserver when my store front is unloaded (in viewDidUnload of my store front)... Is it a correct way?

Normally where you all addTransactionObserver?

Please let me know if my questions are not clear. Any comments and suggestions are welcome. Thanks a lot. :)
 
You will not get a crash as long as your observer is still around. This goes for all and any observer. In your case it sounds like the observer is the appdelegate. The appdelegate will be around for the duration of your app so it's perfectly safe in your case to do sweet nuthin'. If you want to dot your i's and cross your t's you can remove the observer in the dealloc.

If you are setting some viewcontroller to be the observer however you will need to remove it as you navigate away from the viewcontroller. This type of thing should probably be sitting in some model object though. My preference would be to have some singleton to deal with the inapp purchase stuff.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.