您可能获得多个回调的原因是您无意中注册了多个观察者 . 如果要实例化在付款队列中注册为观察者的视图控制器,则需要确保在事务完成时将其删除 .
处理此类情况的更好方法可能是让单个观察者将通知发送回您的控制器 .
@implementation MyViewController : SomeParentController
- (void)startPayment:(SKPayment *)payment {
SKPaymentQueue *queue = [SKPaymentQueue defaultQueue];
/* Unless MyViewController is a singleton this line of code will add a new observer
* to the default queue. The observer is retained and every time a transaction is added
* to the queue the callback code will be executed on all registered observers.
*/
[queue addTransactionObserver:self];
[SKPaymentQueue addPayment:payment];
}
- (void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions {
// Your transaction processing code here
}
@end