ios – paymentQueue:(SKPaymentQueue *)队列updatedTransactions :( NSArray *)事务在restoreCompletedTransactions时不被调用

前端之家收集整理的这篇文章主要介绍了ios – paymentQueue:(SKPaymentQueue *)队列updatedTransactions :( NSArray *)事务在restoreCompletedTransactions时不被调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨我需要在Inapp-Purchase中实现恢复功能,为此创建了一个“恢复”按钮,它是调用方法
-(void)restorePurchasedProductsWithProductId:(NSString*)prodID
{
    _productIdsArray = [[NSMutableArray alloc] init];
    productID = [prodID retain];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

它给了我一个输入苹果id密码的弹出窗口.在这之后没有任何反应.

我读到了它所调用的地方

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

所以我喜欢这样

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    NSLog(@"paymentQueue");
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self FailedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"restored");
                [self restoreTransaction:transaction];
                break;
            default:
                break;

        }
    }
}

但问题是上面的方法并没有调用这个

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue

也不

-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error

我还包括了所需的协议,

有些正文可以帮助我为什么这些委托方法不会要求恢复过程.
我正在尝试使用测试帐户.

解决方法

您需要确保实现paymentQueueRestoreCompletedTransactionsFinished的类:和paymentQueue:restoreCompletedTransactionsFailedWithError:被注册为您的支付队列的观察者.

如果您已在UIViewController中编写此代码,请尝试在viewDidLoad中添加代码

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

并在viewDidDisappear中:

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
原文链接:https://www.f2er.com/iOS/332431.html

猜你在找的iOS相关文章