问题
I use this tutorial http://www.raywenderlich.com/2797/introduction-to-in-app-purchases for create purchases in my app.
From time to time this code is working or not working. I know it sounds funny, but this is my problem.
For example: First start app (all items download and shows in table and i have available to purchase any of this), but at the next time (for example second start) I get an error on this line:
SKProduct *product = [[InAppRageIAPHelper sharedHelper].products objectAtIndex:0];
The error is
Terminating app due to uncaught exception 'NSRangeException' index 0 beyond bounds for empty array
回答1:
If you want to avoid this kind of crash just put a condition before processing the product like this:
if ([[InAppRageIAPHelper sharedHelper].products count] >0)
{
SKProduct *product = [[InAppRageIAPHelper sharedHelper].products objectAtIndex:0];
//product processing goes here
}
else
{
NSLog (@"Warning: no products returned");
}
回答2:
use this Code when you use the payment method.....like payment button pressed
NSLog(@"Products - %@",[IAPClockDietHelper sharedHelper].products);
You found , when You start App First time then You have products valve...and when You use app Second time then Products have NULL Value....So Your Application is Crash ...check ..
回答3:
This problem I solved after make hard reset for my device.
来源:https://stackoverflow.com/questions/9158778/in-app-purchase-not-work