I am implementing in app purchase feature for a bookshelf but an error message RANDOMLY appear during purchasing books.
The error message is "Payment requests are restricted to products returned as valid via Store Kit's didReceiveResponse method."
I find the document in apple http://developer.apple.com/library/ios/#qa/qa2010/qa1691.html but it does not help to solve the problem...
in the same time observer print out another error : "Can't connect to the iTunes Store".
my in app purchase logic flow:
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];
}
}
Observer:
- (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;
}
}
}