应用程序崩溃[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

时间:2023-01-12 21:47:56

应用程序崩溃[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

That's all I can get from the crash when I do in the applicationDidBecomeActive

当我在applicationDidBecomeActive中执行操作时,我可以从崩溃中获得所有这些

MyStoreObserver * observer = [[MyStoreObserver alloc] initWithContext:self.managedObjectContext andDelegate:self];

[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

But the weird thing is I have been able to purchase twice in the past and even if I delete the app re-reun everything I cannot escape this pit. It doesn't seems logic. I can alloc init the observer alone without problem and I can call the default paymentQueue without problem but if I try to add the transaction observer to the queue, life stop. It's on ARC and the delegate I added to the observer is not the problem. I know for sure.

但奇怪的是,我过去已经能够购买两次了,即使我删除了应用程序重新恢复的一切,我无法逃脱这个坑。这似乎不是逻辑。我可以毫无问题地单独为init分配观察者,我可以毫无问题地调用默认的paymentQueue但是如果我尝试将事务观察者添加到队列中,则生命停止。它在ARC上,我添加给观察者的代表不是问题。我肯定知道。

I've added an nslog to every method in the observer and none get called before the crash

我已经为观察者中的每个方法添加了一个nslog,并且在崩溃之前没有被调用

SOLUTION FOUND

Okay, well it looks like the observer is not retained by the queue and thus the observer needs to be an instance variable.

好吧,看起来观察者不会被队列保留,因此观察者需要成为一个实例变量。

Thanks

2 个解决方案

#1


10  

Okay, well it looks like the observer is not retained by the queue and thus the observer needs to be an instance variable (or retained in some way).

好吧,好像看起来观察者没有被队列保留,因此观察者需要是一个实例变量(或以某种方式保留)。

#2


1  

To add an official source to this answer:

要为此答案添加官方来源:

Inside the header file SKPaymentQueue.h of the Framework Storekit is the following clear comment:

在Framework Storekit的头文件SKPaymentQueue.h中,有以下明确的注释:

// Observers are not retained.
// The transactions array will only be synchronized with the server while the queue has observers.
// This may require that the user authenticate.
- (void)addTransactionObserver:(id <SKPaymentTransactionObserver>)observer __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

#1


10  

Okay, well it looks like the observer is not retained by the queue and thus the observer needs to be an instance variable (or retained in some way).

好吧,好像看起来观察者没有被队列保留,因此观察者需要是一个实例变量(或以某种方式保留)。

#2


1  

To add an official source to this answer:

要为此答案添加官方来源:

Inside the header file SKPaymentQueue.h of the Framework Storekit is the following clear comment:

在Framework Storekit的头文件SKPaymentQueue.h中,有以下明确的注释:

// Observers are not retained.
// The transactions array will only be synchronized with the server while the queue has observers.
// This may require that the user authenticate.
- (void)addTransactionObserver:(id <SKPaymentTransactionObserver>)observer __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);