应用内购买:视图消失时崩溃

发布于 2024-12-07 20:09:54 字数 225 浏览 0 评论 0原文

我的应用程序有一个包含 4 个视图控制器的选项卡栏。第三个视图控制器包含“商店应用内购买”。在此控制器中,我使用一个管理应用内购买(产品请求、购买、交易等)的对象,该对象允许我获取并显示价格说明 ecc。

问题是:如果我在请求启动时更改选项卡,应用程序有时会崩溃,但并非总是如此。

我必须在 viewDidDisappear 中取消请求吗? [productsRequest cancel] 此代码崩溃。

My application has a tabbar that contains 4 view controllers. The third view controller contains a "store in-app purchases". In this controller I use an object that manages in-app purchases (product request, purchase, transaction etc...) that allow me to get and show price description ecc.

The problem is: If I change tabs while the request started the app crashes sometimes, but not always.

I've to cancel the request in viewDidDisappear?
[productsRequest cancel] this code crashes.

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

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

发布评论

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

评论(3

裂开嘴轻声笑有多痛 2024-12-14 20:09:55

我有同样的问题。
要修复它,请取消请求,一切都会好起来的。

var request: SKProductsRequest! //global to cancel when disappear
//request products when you want (viewDidLoad for example)
   request = SKProductsRequest(productIdentifiers: productID as! Set<String>)
            request.delegate = self
            request.start()

当视图控制器消失时:

 override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        request.delegate = nil;
        request.cancel()
        SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
    }

I have the same issue.
To fix it cancel request and all be fine.

var request: SKProductsRequest! //global to cancel when disappear
//request products when you want (viewDidLoad for example)
   request = SKProductsRequest(productIdentifiers: productID as! Set<String>)
            request.delegate = self
            request.start()

And when disapear viewcontroller:

 override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        request.delegate = nil;
        request.cancel()
        SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
    }
鼻尖触碰 2024-12-14 20:09:55

您的问题可能与应用内购买无关。在代码中的某个位置,您正在向已释放的对象发送消息。运行分析器可以帮助您找到错误,但这次可能没有必要。如果 [productsRequest cancel] 崩溃,则 productsRequest 的保留计数可能太低。

Your problem has probably nothing to do with in-app purchase. Somewhere in your code you're sending a message to an object which has been released. Running the analyzer can help you find the bug, but it may not be necessary this time. If [productsRequest cancel] crashes, then probably productsRequest has too low retain count.

她比我温柔 2024-12-14 20:09:55

viewDidDisappear 时删除 TransactionObserver

[[SKPaymentQueue defaultQueue]removeTransactionObserver:self];

如果您从 Inapp 视图控制器返回到另一个视图控制器,则

[[SKPaymentQueue defaultQueue]removeTransactionObserver:self];
[self dismissViewControllerAnimated:YES completion:NULL];

Remove the TransactionObserver while your viewDidDisappear:

[[SKPaymentQueue defaultQueue]removeTransactionObserver:self];

If you go back from the Inapp viewcontroller to another viewcontroller,then

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