检测取消按钮点击"确认您的应用程序内购买"UIAlert

Vad*_*Vad 7 iphone xcode objective-c storekit in-app-purchase

我根据教程实现了应用内购买.我遇到的问题是,我无法检测到"确认您的应用程序内购买"警报时按下取消按钮,这是StoreKit框架的一部分.

一些来源建议-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions在按下取消时调用,但在我的情况下它永远不会运行.我的设置是ViewController,它导入符合SKProductRequestDelegate和SKPaymentTransactionObserver的IAPManager:NSObject类.产品成功被请求,但事务观察者从不打电话paymentQueue.

如何让它工作,以便我可以检测取消按钮?

met*_*eth 13

在委托方法中,我看一下教程,如果用户取消,则failtransaction不会执行任何操作.但你可以这样添加它.

- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        // error!
          NSLog(@"Something went Wrong!");
        [self finishTransaction:transaction wasSuccessful:NO];
          NSLog(@"transaction error :%@", transaction.error.localizedDescription);
    }
    else
    {
          NSLog(@"Cancelled");
        // this is fine, the user just cancelled
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    }
}
Run Code Online (Sandbox Code Playgroud)


bde*_*ham 0

我没有使用过 StoreKit,但我猜如果用户取消,您SKRequestDelegate会收到该消息。request:didFailWithError: