In app purchase not work

左心房为你撑大大i 提交于 2019-12-23 05:33:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!