我正在实施书架的应用购买功能,但在购买图书时会出现错误消息。
错误消息是 “付款请求仅限于通过Store Kit的didReceiveResponse方法返回的有效产品。”
我在苹果中找到该文件 http://developer.apple.com/library/ios/#qa/qa2010/qa1691.html 但它没有帮助解决问题...
同时观察者打印出另一个错误:“无法连接到iTunes Store”。
我的应用内购买逻辑流程:
APP START:
- (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
}
PURCHASE:
- (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;
}
}
}
答案 0 :(得分:2)
看起来问题不在你身边。根据{{3}},您的代码很好。
答案 1 :(得分:1)
尝试更改:
SKPayment *payment = [SKPayment paymentWithProduct:[response.products objectAtIndex:0]];
为:
SKPayment *payment = [SKPayment paymentWithProductIdentifier:[response.products objectAtIndex:0].productIdentifier];
我和你有同样的问题,这个改变对我有用。