【问题标题】:Apple In app purchase StoreKit errorApple 应用内购买 StoreKit 错误
【发布时间】:2010-11-03 13:48:13
【问题描述】:

我正在为书架实现应用内购买功能,但在购买书籍期间随机出现错误消息。

错误信息是 “付款请求仅限于通过 Store Kit 的 didReceiveResponse 方法返回为有效的产品。”

我在苹果中找到了文档 http://developer.apple.com/library/ios/#qa/qa2010/qa1691.html 但这无助于解决问题...

同时观察者打印出另一个错误:“无法连接到 iTunes Store”。

我的应用内购买逻辑流程:

应用开始:

- (void) requestProductDataWithSet:(NSSet*)_set
{
 SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: _set];
 request.delegate = self;
 [request start];
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    //setup UI here
}

购买:

- (void) purchase:(SKProduct *)product
{
 if (!product || !verified) {
  return;
 }

 SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:product.productIdentifier]];
 request.delegate = self;
 [request start];
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
if ([SKPaymentQueue canMakePayments] && [response.products count] > 0)
{
    NSLogInfo(@"xxxxxxxxx Make payment xxxxxxxxx");
    SKPayment *payment = [SKPayment paymentWithProduct:[response.products objectAtIndex:0]];
    [[SKPaymentQueue defaultQueue] addPayment:payment];   
  }
  else
  {
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase" message:@"You are not authorized to purchase from AppStore"
                 delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
   [alert show];
   [alert release];
  }
    }

观察者:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
 for (SKPaymentTransaction *transaction in transactions)
 {
  NSLogInfo(@"updatedTransactions transactionState:%d, productIdentifier:%@",transaction.transactionState,transaction.payment.productIdentifier);
  switch (transaction.transactionState)
  {
   case SKPaymentTransactionStatePurchased:

                [self completeTransaction:transaction];

                break;

            case SKPaymentTransactionStateFailed:

                [self failedTransaction:transaction];

                break;

            case SKPaymentTransactionStateRestored:

                [self restoreTransaction:transaction];

            default:

                break;
  }   
 }
}

【问题讨论】:

    标签: iphone in-app-purchase storekit


    【解决方案1】:

    看来问题不在您这边。根据Technical Q&A QA1691,您的代码很好。

    【讨论】:

    【解决方案2】:

    尝试改变:

    SKPayment *payment = [SKPayment paymentWithProduct:[response.products objectAtIndex:0]];
    

    到:

    SKPayment *payment = [SKPayment paymentWithProductIdentifier:[response.products objectAtIndex:0].productIdentifier];
    

    我和你有同样的问题,这个改变对我有用。

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      相关资源
      最近更新 更多