在应用程序购买不适用于iOS与月度订阅产品

时间:2014-09-29 10:10:20

标签: ios iphone in-app-purchase

我已经为In App Purchase做了以下代码,但是当它提示输入App Store UserId和Password时,它会触发 - (void)paymentQueue:(SKPaymentQueue *)队列updatedTransactions:(NSArray *)事务  方法与SKPaymentTransactionStatePurchased两次或任意次数。现在和我的情况很奇怪。我也试过IAP库但结果相同。我有使用相同代码但不使用月度订阅产品的非消费品的In App Purchase。

在下面的代码中,“30”是产品ID。

-(void)requestProducts{
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"30"]];
request.delegate = self;
[request start];
}



-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSLog(@"%@", response.products);

[self performSelector:@selector(startTransaction:) withObject:[response.products objectAtIndex:0] afterDelay:1];
}

-(void)startTransaction:(SKProduct *)product{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void) failedTransaction: (SKPaymentTransaction *)transaction{
NSLog(@"failedTransaction");
if (transaction.error.code != SKErrorPaymentCancelled)
{
    NSLog(@"Cancelled");
    // Optionally, display an error here.
}else if (transaction.error.code != SKErrorPaymentInvalid){
    NSLog(@"Invalid");
}else if (transaction.error.code != SKErrorPaymentNotAllowed){
    NSLog(@"Not Allowed");
}else if (transaction.error.code != SKErrorClientInvalid){
    NSLog(@"ClientInvalid");
}else if (transaction.error.code != SKErrorStoreProductNotAvailable){
    NSLog(@"ProductNotAvailable");
}else if (transaction.error.code != SKErrorUnknown){
    NSLog(@"Unknown");
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction{
NSLog(@"restoreTransaction");
//[self recordTransaction: transaction];
//[self provideContent: transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) completeTransaction: (SKPaymentTransaction *)transaction{
NSLog(@"completeTransaction");
// Your application should implement these two methods.
//[self recordTransaction: transaction];
//[self provideContent: transaction.payment.productIdentifier];
// Remove the transaction from the payment queue.
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

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

1 个答案:

答案 0 :(得分:0)

你说你正在做一个"月度订阅产品"。如果这是一个可自动更新的IAP,则每次从新测试用户购买将产生5-6个续订交易,每5分钟一个。如果你等待30分钟,你会期望5或6次调用updatedTransactions