我在 Cocos2d 应用程序中的哪里附加 StoreKit 委托和观察者?
我已经弄清楚了 StoreKit 的所有内容是如何工作的,并且已经实际测试了工作代码......但是,我有一个问题。
我将“商店”图层/场景设为 SKProductsRequestDelegate
。这是正确的做法吗?我得到的初始产品信息如下:
SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: productIDs];
[productRequest setDelegate: self];
[productRequest start];
问题是,如果我在请求正在进行时转换到新场景,则当前层将由 ProductRequest 保留。这意味着对我的新场景/图层的触摸是由新图层和旧图层处理的。
我可以在离开现场时取消 ProductRequest,但是:
- 我不知道此时它是否正在进行。
- 我无法释放它,因为它可能已被请求代表释放,也可能没有被释放。
必须有更好的方法来做到这一点。我可以使委托成为当前层外部的类,但随后我不知道如何在调用处理程序时使用产品信息轻松更新层。
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:
- I do not know if it is in progress at that point.
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,问题解决了......呃。
我继续将商店创建为一个单独的类,并通过向该类添加委托来解决场景的回调问题,该类保存了商店接口的层。当事务完成时,我可以使用委托回调我的场景/图层。
在尝试向委托发送消息之前,我通过使用
respondsToSelector:
方法解决了不知道委托是否已被释放的问题。事实证明,真正的错误是由我尝试修复 1 & 引起的。 2 首先。我重写了 onExit 来让我知道何时删除作为存储委托的类。结果我忘了调用
[super onExit]
,这是场景释放的地方。因此,它保持保留并且没有从 touchHandler 中删除。哎呀!OK, problem solved.... ergh.
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.
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.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!