用户购买商品后,输入邮箱和密码并付款,从不调用updatedTransactions方法。该项目是定期购买的,但如果不调用 updatedTransactions 方法,我无法执行代码以将项目添加到应用程序。我注意到该项目已被购买,因为如果我运行代码来恢复购买的项目,一切都会正常,并且该产品会安装到应用程序中。
这是我复制的购买产品的代码:
-(IBAction)buyProductid)sender {
NSLog(@"urchasing: %@", self.product.productIdentifier);
SKPayment *payment = [SKPayment paymentWithProduct:self.product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
按照代码恢复产品:
-(IBAction)restoreProductid)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
我注意到在最后一段代码中我有以下行:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
我也应该在购买部分添加这条线吗?
我通过在 buyProduct 方法中添加以下代码解决了这个问题:
-(IBAction)buyProductid)sender {
NSLog(@"urchasing: %@", self.product.productIdentifier);
SKPayment *payment = [SKPayment paymentWithProduct:self.product];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; //added line
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
现在在付款前和付款后调用方法 updatedTransactions。
使用以下代码,您可以检查一切是好是坏:
for(SKPaymentTransaction *transaction in transactions) {
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
[self unlockRemoveiAD];
[OKalertView show];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
if (transaction.transactionState == SKPaymentTransactionStateFailed) {
[alertView show];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
}
关于ios - 为什么从不调用updatedTransactions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33895799/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |