我在 Cocos2d 应用程序中的哪里附加 StoreKit 委托和观察者?

发布于 2024-09-01 07:11:58 字数 609 浏览 6 评论 0原文

我已经弄清楚了 StoreKit 的所有内容是如何工作的,并且已经实际测试了工作代码......但是,我有一个问题。

我将“商店”图层/场景设为 SKProductsRequestDelegate。这是正确的做法吗?我得到的初始产品信息如下:

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

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

问题是,如果我在请求正在进行时转换到新场景,则当前层将由 ProductRequest 保留。这意味着对我的新场景/图层的触摸是由新图层和旧图层处理的。

我可以在离开现场时取消 ProductRequest,但是:

  1. 我不知道此时它是否正在进行。
  2. 我无法释放它,因为它可能已被请求代表释放,也可能没有被释放。

必须有更好的方法来做到这一点。我可以使委托成为当前层外部的类,但随后我不知道如何在调用处理程序时使用产品信息轻松更新层。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄傲 2024-09-08 07:11:58

好的,问题解决了......呃。

  1. 我继续将商店创建为一个单独的类,并通过向该类添加委托来解决场景的回调问题,该类保存了商店接口的层。当事务完成时,我可以使用委托回调我的场景/图层。

  2. 在尝试向委托发送消息之前,我通过使用 respondsToSelector: 方法解决了不知道委托是否已被释放的问题。

  3. 事实证明,真正的错误是由我尝试修复 1 & 引起的。 2 首先。我重写了 onExit 来让我知道何时删除作为存储委托的类。结果我忘了调用[super onExit],这是场景释放的地方。因此,它保持保留并且没有从 touchHandler 中删除。哎呀!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文