views:

119

answers:

1

I have figured out how all of the StoreKit stuff works and have actually tested working code... however, I have a problem.

I made my "store" layer/scene the SKProductsRequestDelegate. Is this the correct thing to do? I get the initial product info like so:

SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: productIDs];

[productRequest setDelegate: self];
[productRequest start];

The problem is that if I transition to a new scene when a request is in progress, the current layer is retained by the productRequest. This means that touches on my new scene/layer are handled by both the new layer and the old layer.

I could cancel the productRequest when leaving the scene, but:

  1. I do not know if it is in progress at that point.
  2. I cannot release it because it may or may not have been released by the request delegates.

There has got to be a better way to do this. I could make the delegate a class external to the current layer, but then I do not know how to easily update the layer with the product information when the handler is called.

A: 

OK, problem solved.... ergh.

  1. I went ahead and made the store a separate class, and solved the issue of callbacks to the scene by adding a delegate to the class, which holds the layer of the Store interface. When the transactions finish, I can use the delegate to call back to my scene/layer.

  2. I solved the issue of not knowing if the delegate has been released by using the respondsToSelector: method before attempting to send a message to it.

  3. It turns out the real bug was caused by my attempt to fix 1 & 2 in the first place. I overrode onExit to let me know when to remove the class as the store delegate. It turns out I forgot to call [super onExit], which is where the scene is released. Hence, it stayed retained and did not get removed from the touchHandler. Oops!

Jeff B