应用内购买测试用户不起作用

时间:2012-08-14 21:33:17

标签: ios xcode in-app-purchase

我在使应用内购买工作时遇到问题。我每次创建一个新的测试用户并在我的iPhone上调试它之后我会自动获得“你已经购买了这个,但它还没有被下载。”

我已将此添加到我的viewDidLoad:

 [[SKPaymentQueue defaultQueue] addTransactionObserver:self];

我的购买功能如下:

- (IBAction)purchaseProduct:(id)sender { 
        SKProduct *product = [productArray objectAtIndex:0];  
        SKPayment *payment = [SKPayment paymentWithProduct:product];
       [[SKPaymentQueue defaultQueue] addPayment:payment];
 }

我也有:

-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions) {

    if ([transaction transactionState] == SKPaymentTransactionStatePurchased) {
      [self transactionDidComplete:transaction];


    } else if ([transaction transactionState] == SKPaymentTransactionStateFailed) {
        [self transactionDidFail:transaction];

    } else if ([transaction transactionState] == SKPaymentTransactionStateRestored) {
        [self transactionDidRestore:transaction];

    } else {

        NSLog(@"Unhandled case: %@", transaction);

    }
}

}

只要我在没有输入测试用户帐户密码的情况下点击购买按钮,我就会收到此错误:

Unhandled case: <SKPaymentTransaction: 0x25a9a0>

这意味着,我假设在我输入密码之前正在调用支付队列,并且可以进行购买!

我在函数“transactionDidComplete,transactiondidFail,transactionDidRestore”中有以下代码

 [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

1 个答案:

答案 0 :(得分:1)

您需要处理SKPaymentTransactionStatePurchasing

类似的东西:

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
  //NSLog(@"updatedTransactions %@",transactions);
  NSNumber *paymentOk = [NSNumber numberWithBool:NO];
  for(SKPaymentTransaction *t in transactions){
    //transaction failed
    if(t.transactionState == SKPaymentTransactionStateFailed){
      //[self doTransactionFailure:t.error.localizedDescription];
      [[SKPaymentQueue defaultQueue] finishTransaction:t];
      continue;
    }
    if(t.transactionState == SKPaymentTransactionStatePurchasing){
      continue;
    }
    //transaction type here is success or restored
    //extract the app object
    if([t.payment.productIdentifier caseInsensitiveCompare:self.inAppPurchaseIdentifier]== NSOrderedSame){
      NSLog(@"Got payment for %@",t.payment.productIdentifier);
      paymentOk = [NSNumber numberWithBool:YES];
    }
    [[SKPaymentQueue defaultQueue] finishTransaction:t];
  }
  if([paymentOk boolValue]==YES){
    [self.delegate didPurchaseWithIdentifier:self.inAppPurchaseIdentifier];
  }
  else{
    [self.delegate didFailPurchaseWithIdentifier:self.inAppPurchaseIdentifier andReason:@"Unknown"];
  }
}