objective-c - 应用内购买崩溃应用

标签 objective-c iphone in-app-purchase app-store

我有一个 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/

相关文章:

ios - 如何在Objective-C中将NSMutableArray的元素设置为UILabel?

objective-c - Apple LLVM 编译器是否优化了重复的属性访问?

Ios SKSpriteNode 防止负 x 速度

ios - 尝试创建一个表单以将联系人添加到设备——我该如何处理空白字段?

android - 尽管另一个高度赞成的 SO 说我不会在测试期间,但在为 IAP 收费后需要帮助

ios - NSOuputStream发送旧值- objective-c

ios - 在此设备上启用开发时遇到错误

iphone - Storyboard中具有不同标识符和不同高度的两个 UITableViewCell

ios - 在 App Store 上验证应用内购买的收据

ios - 方法未到达完成 block