我已经实现了 Apple 文档中关于 IAP 中描述的应用内付款,但是当我在沙盒模式下尝试它们时,“transactionState”永远不会更改为 SKPaymentTransactionStatePurchased。(它永远保留在 SKPaymentTransactionStatePurchasing 上。)
有人知道出了什么问题吗?
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
NSLog(@"%ld", transaction.transactionState);
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
[self recordTransaction:transaction];
[self provideContent:transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled) {
[NSAlert alertWithError:transaction.error];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
[self recordTransaction:transaction];
[self provideContent:transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)recordTransaction:(SKPaymentTransaction *)transaction
{
NSLog(@"Record Transaction...");
// ToDo: Implement 'recordTransaction'.
}
- (void)provideContent:(NSString *)productIdentifier
{
NSLog(@"Provide Content");
// ToDo: Implement 'provideContent'.
}