iPhone - SKProductsRequest和“发送到解除分配的实例的消息” [英] iPhone - SKProductsRequest and "message sent to deallocated instance"
问题描述
我遇到了实施InAppPurchase的麻烦。我的购买实现是在模态视图控制器(AppUpgradeViewController)中,我从另一个模态视图中呈现。我是这样做的:
I got troubles implementing InAppPurchase. My implementation of purchase is in modal view controller (AppUpgradeViewController), that I present from another modal view. I do it like this:
AppUpgradeViewController * appUpgradeViewController = [[AppUpgradeViewController alloc] init];
appUpgradeViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
appUpgradeViewController.delegate = self;
[self presentModalViewController:appUpgradeViewController animated:YES];
[appUpgradeViewController release];
然后,在我的升级视图中,我执行以下操作:
Then, in my upgrade view I do the following:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
NSSet *productIdentifiers = [NSSet setWithObject:kInAppPurchaseProUpgradeProductId];
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.productsRequest.delegate = self;
[productsRequest start];
然后我实施了
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
我在哪里:
[self.productsRequest release];
然后我还有其他必需的方法。
and then I have other required methods.
问题是当我显示模态时,并迅速解除它然后几秒后我在控制台上得到以下内容(我打开了NSZombieEnabled):
The problem is when I show modal, and quickly dismiss it then after few seconds i got the following on console (I turned on NSZombieEnabled):
*** -[AppUpgradeViewController respondsToSelector:]: message sent to deallocated instance 0x2e91f0
我想这是产品请求的内容,但我不知道如何调试或修复它。似乎请求的答案是在它被解除(并且被解除分配)之后才到达该控制器,但是我不知道在解除/ dealloc之后如何阻止它接收消息。
感谢您的帮助!
I suppose that it's something with that product request, but I don't know how to debug or fix it. It seems that the answer for request comes to this controller just after it's dismissed (and deallocated), but I don't know how to prevent it from receiving messages after dismiss/dealloc. Thanks for any help!
推荐答案
我遇到了同样的问题。不是模态视图,而是导航控制器堆栈上的推入视图。当我在通过 SKProductsRequest
加载产品信息之前快速导航回来时,它还会向我发送一个消息,发送到解除分配的实例
例外。我通过调用 cancel
方法解决了这个问题(参见参考。
I had the same problem. Not with a modal view, but with a pushed view on the navigation controller stack. When I quickly navigated back before my product information was loaded via SKProductsRequest
, it also throws me an message sent to deallocated instance
exception. I solved this by calling the cancel
method (see reference) on my SKProductsRequest object.
除此之外,我还将代表设置为 nil
。
Additional to this I also set the delegate to nil
.
这是我的产品请求:
NSSet *productIdentifiers = [NSSet setWithObject:@"MY_IDENTIFIER"];
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
这是我在dealloc方法中用来取消它的方法。
and this is what I called in the dealloc method to cancel it.
productsRequest.delegate = nil;
[productsRequest cancel];
productsRequest = nil;
我还从 SKPaymentQueue
中删除了观察者如另一个问题的答案中所述。
I also removed the observer from the SKPaymentQueue
like described in this answer for another question.
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
这篇关于iPhone - SKProductsRequest和“发送到解除分配的实例的消息”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!