我有一个 iOS 应用程序,我刚刚提交了更新。该应用程序的开发版本(模拟器和我的 4S)从未崩溃,并且运行良好。该应用程序和 IAP 今天都获得了批准,但今天早上我意识到 iAP 尚未“获准购买”。我刚刚清除它以供购买,但该应用程序仍然崩溃。 iPhone给出的错误(运行app store版本)给出的错误:
<Error>: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
这是发生这种情况的代码:
- (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];
}
}
在请求可用产品列表时会发生这种情况,这显然会在模拟器中而不是在应用程序中返回产品。我刚刚添加了针对此的保护措施,但我需要再次将其提交到 App Store。
有谁知道为什么 iAP 没有出现在 App Store 版本中?我是否需要等待“允许销售”选项才能转到 Apple 的服务器?谢谢!
最佳答案
显然 myProduct
数组是空的。为什么会发生这种情况是另一个问题,但在未确保请求的索引存在的情况下,您永远不应调用 objectAtIndex
。
if ([myProduct count] > 0)
noAdProduct = [myProduct objectAtIndex:0];
else
// Deal with the situation when the array is empty.
关于objective-c - 应用内购买崩溃应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13501876/