2 つのバンドル ID を作成するアプリ内購入を設定しました。テスト アカウントを作成し、アプリ内購入を確認しました。1 週間後にテストしたところ、このエラーが発生*** 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;
}
}
}