当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - In-app purchase fails after telling "item already bought" message

问题描述:

I am building an iOS app and trying to implement an in app purchase (non-consumable).

All the bundle IDs etc. are set up and working, and I can see my product as valid when I fetch the Apple Store servers. However, while testing, I am getting failed transactions at the paymentQueue callback.

Here is what happens in the iOS simulator step by step:

  1. A message box asks "would you like to buy .. for $0.99?" which is correct
  2. I click Yes.
  3. After about a second it says that I've already bought it (correct, I test-bought it initially while debugging). I click OK.
  4. It complains about a login requirement (it says something like MZFinance_LoginRequired, I think its a missing string identifier.) I click OK.
  5. App Store login box pops up and I enter my test account credentials.
  6. My breakpoint in Xcode is hit, with the transaction state SKPaymentTransactionStateFailed.

Here is the relevant part of my code:

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{

NSArray* arr = response.products;

for (int i = 0; i < arr.count; i++) {

SKProduct* product = [arr objectAtIndex:i];

if([product.productIdentifier isEqualToString:@"<<my in app purchase id which is correct and working>>"]){

SKPayment *payment = [SKPayment paymentWithProduct:product];

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

[[SKPaymentQueue defaultQueue] addPayment:payment];

}

}

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{

for (SKPaymentTransaction* ta in transactions) {

switch (ta.transactionState) {

case SKPaymentTransactionStatePurchased:

case SKPaymentTransactionStateRestored:

receipt = [ta transactionReceipt];

[self performSelectorInBackground:@selector(validateFromServer) withObject:nil];

break;

case SKPaymentTransactionStateFailed:

[self purchaseFailed];

break;

}

if(!ta.transactionState == SKPaymentTransactionStatePurchasing){

[[SKPaymentQueue defaultQueue] finishTransaction:ta];

}

}

}

}

[self purchaseFailed] always gets hit, which just notifies the user. What can be wrong here? (I am new to iOS and -obviously- iOS in app purchases).

Thanks.

UPDATE: My test account credentials are correct, as I am getting a different (invalid login) message if I type it wrong.

网友答案:

sorry about the late answer and I know you already solved yours, but I had this problem too. My solution was to automatically run the restore purchase method since that seemed to work.

Thanks

网友答案:

After some time struggling with it, I've noticed that I'm not encountering any problems in production. It was probably a problem with the sandbox servers.

分享给朋友:
您可能感兴趣的文章:
随机阅读: