应用内购买:视图消失时崩溃 [英] In-App Purchases: Crash when view disappear

查看:118
本文介绍了应用内购买:视图消失时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个包含4个视图控制器的标签栏。第三个视图控制器包含商店应用内购买。在这个控制器中,我使用一个管理应用程序内购买的对象(产品请求,购买,交易等......),这些对象允许我获取并显示价格描述ecc。

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.

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

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

推荐答案

我遇到同样的问题。
修复它取消请求,一切正常。

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()

当disapear viewcontroller:

And when disapear viewcontroller:

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

这篇关于应用内购买:视图消失时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆