In the App Purchase Crashes App

I have an iOS app that I just submitted for an update. The application development version (simulator and my 4S) never crashed, and everything works fine. The app was approved today as well as the IAP, but this morning I realized that the iAP was not “cleaned up for purchase.” I just cleared it for a purchase, but the application is still crashing. The error that the iPhone gives (launching the application store version) gives the error:

<Error>: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'

Here is the code where this happens:

 - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response { NSArray *myProduct = response.products; //this line is where the error occurs noAdProduct = [myProduct objectAtIndex:0]; if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"the id here"] boolValue]) { adCell.detailTextLabel.text = [NSString stringWithFormat:@"$%@", noAdProduct.price]; adCell.userInteractionEnabled = YES; adCell.accessoryType = UITableViewCellAccessoryNone; adCell.accessoryView = nil; [self.tableView reloadData]; } } 

This happens when you request a list of available products, which obviously returns the product in the simulator, but not in the application. I just added protection against this, but I will need to send it to the App Store again.

Does anyone know why iAP does not appear in the version of the App Store? Do I have to wait until the “cleared for sale” option appears on Apple's servers? Thanks!

+4
source share
1 answer

Obviously, the myProduct array myProduct empty. Why this is happening is another question, but you should never call objectAtIndex without making the requested index exist.

 if ([myProduct count] > 0) noAdProduct = [myProduct objectAtIndex:0]; else // Deal with the situation when the array is empty. 
0
source

Source: https://habr.com/ru/post/1447593/


All Articles