我设置了我的应用内购买,创建了两个捆绑 ID。我创建了一个测试帐户并检查了我的应用内购买..它工作得非常好......一周后当我测试我得到这个错误*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** 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;
}
}
}