i set my in app purchase creating two bundle id’s .i created a test account and checked my in app purchase..it was working perfectly fine…after a week later when i tested i m getting this error *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array' and its not returning the products…could u guys help me out.what possibly could be wrong with this
*** First throw call stack:
-(void)Declarations
{
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"parental functions are disabled");
SKProductsRequest *productRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObjects:@"com.techzone.9xo.onedollar",@"com.techzone.9xo.twodollar",nil]];
productRequest.delegate=self;
[productRequest start];
}else {
NSLog(@"parental functions are enabled");
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response
{
SKProduct *validProduct=nil;
int count = [response.products count];
NSLog(@"number of prouducts present:%d",count);
if(_HintValue)
{
validProduct = [response.products objectAtIndex:0];
}
if (!_HintValue) {
validProduct = [response.products objectAtIndex:1];
}
NSLog(@"the product is :%@",validProduct.localizedTitle);
SKPayment *skpayment = [SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addPayment:skpayment];
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
}
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
NSLog(@"stuff is getting purchased");
break;
case SKPaymentTransactionStatePurchased:
NSLog(@"purchased properly");
NSInteger currentValue=[Util getIntegerValueForKey:@"hintValue"];
if(_HintValue)
[Util setIntegerValue:10+currentValue forKey:@"hintValue"];
if (!_HintValue)
[Util setIntegerValue:25+currentValue forKey:@"hintValue"];
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"error happened");
}
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
default:
break;
}
}
}
The problem is that you are getting an empty list of valid product IDs. You are accessing
objectAtIndex:0of an empty array which creates that error.if you check
response.invalidProductIdentifiersyou will find your product IDs there.Unfortunately that can have many reasons. Have a look at this checklist of reasons that can lead to invalid product IDs.