简体   繁体   English

苹果拒绝了我的应用程序在iPhone 5上崩溃

[英]Apple rejected my app for crashing on iphone 5

I know this question has been asked several times, but Im looking for a more general answer. 我知道这个问题已经问过几次了,但是我正在寻找一个更一般的答案。 I have developed an app for iOS 6, I tested it on simulator(Retina 3.5 and 4 inch) and also on an iPhone 4 device. 我已经为iOS 6开发了一个应用程序,我已经在模拟器(Retina 3.5和4英寸)以及iPhone 4设备上对其进行了测试。 It has never crashed but when I submitted the app to Apple and they answered with: 它从未崩溃过,但是当我将应用程序提交给Apple时,他们回答:

We found that your app crashed upon launch on iPhone 5 running iOS 6.1.3, 我们发现您的应用在运行iOS 6.1.3的iPhone 5上启动时崩溃,

Looking at the crash log 查看崩溃日志 在此处输入图片说明

We see that it crashes in line 164 from a index out of bounds, which makes sense because I have this code there: 我们看到它从索引的第164行崩溃,这是有道理的,因为我在这里有以下代码: 在此处输入图片说明

I added that "if" to stop the execution whenever the indexTimesArray was bigger than the length of the array and see why that happened, but I was unable to reproduce the error. 我添加了“ if”以在indexTimesArray大于数组的长度时停止执行,并查看发生这种情况的原因,但是我无法重现该错误。 I never get an index out of bounds as they do... It's true that I haven't test it on a iPhone 5 device, but I have XCode 4.6 and iOS 6.1 on my computer, and also a iPhone 4 with iOS 6.1.3, but it's also true that the guys at Apple are getting the app crashed, so how to reproduce the error? 我从来没有像他们那样index out of bounds ...的确,我还没有在iPhone 5设备上对其进行测试,但是我的计算机上具有XCode 4.6和iOS 6.1,以及具有iOS 6.1的iPhone 4。 3,但这确实是苹果公司的家伙正在使应用程序崩溃,那么如何重现错误? I tried to install the app from TestFlight because it installs it as a brand new app, just like they do when they test it, but still no errors... 我尝试从TestFlight安装该应用程序,因为它像全新的应用程序一样将其安装为全新应用程序,但是他们仍然没有错误...

How can I reproduce the error? 如何重现错误? Could it be a problem with th build settings? 构建设置可能有问题吗?

Thanks 谢谢

[EDIT] I initialize the contents of timesArray in the init method of the object, like this: [编辑]我在对象的init方法中初始化timesArray的内容,如下所示:

 - (id)init{ self = [super init]; df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd HH:mm"]; rangeDates = [[NSArray alloc]initWithObjects:@"2013-04-11 10:00", @"2013-04-12 10:00", @"2013-04-13 10:00", @"2013-04-14 10:00", nil]; timesArray = [[NSArray alloc]initWithArray:[NSArray arrayWithObjects:@"10:00", @"11:00", @"12:00", @"13:00", @"14:00", @"15:00", @"16:00", @"17:00", @"18:00", @"19:00", @"20:00", @"21:00", @"22:00", nil]]; colorDictio = [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObjects:[UIColor colorWithRed:0.74 green:0.66 blue:0.37 alpha:1.0], [UIColor colorWithRed:0.64 green:0.15 blue:0.11 alpha:1.0], [UIColor colorWithRed:0.313 green:0.65 blue:0.69 alpha:1.0], [UIColor colorWithRed:0.79 green:0.4 blue:0.59 alpha:1.0], [UIColor colorWithRed:0.45 green:0.55 blue:0.53 alpha:1.0], [UIColor colorWithRed:0.14 green:0.27 blue:0.66 alpha:1.0], nil] forKeys:[NSArray arrayWithObjects:@"showers area", @"zinctalks", @"zincnetwork", @"zincshows", @"zinclabs", @"zinczone", nil] ]; return self; } 

To figure out how to reproduce that error you have to look at the code where you create timesArray. 为了弄清楚如何重现该错误,您必须查看在创建timesArray的代码。

The out of bounds error happens because [timesArray count] is less than 2 (or the whole array is nil). 发生越界错误是因为[timesArray count]小于2(或整个数组为nil)。 So you have to figure out which condition leads to an array with one or zero objects. 因此,您必须找出哪个条件导致一个带有一个或零个对象的数组。 Maybe it happens because there is no internet connection. 可能是因为没有互联网连接而发生的。

It's always a good idea to wrap objectAtIndex: in a check for the actual size of the array. 将objectAtIndex:包装在检查数组的实际大小中总是一个好主意。

I would replace else { with else if ([timesArray count] >= 2) { and add an additional else that handles <2 arrays. 我会用else if ([timesArray count] >= 2) {替换else { ,并添加一个处理<2数组的其他else。

First of all this is not a OS related error. 首先,这不是与操作系统相关的错误。 Your app is crashing because the wrong index of array is being accessed. 您的应用程序崩溃是因为访问了错误的数组索引。

  1. How can I reproduce the error? 如何重现错误? : Try to use the same credential which you must have provided to apple. 注意:尝试使用必须提供给Apple的相同凭据。
  2. Could it be a problem with th build settings? 构建设置可能有问题吗? : No. :没有

To debug the error what you can do is try to print the value of indexTimesArray before the if. 要调试该错误,您可以尝试在if之前打印indexTimesArray的值。 Also, try to print all the values you are passing to access the array element. 另外,尝试打印您传递来访问数组元素的所有值。 Which will help you track the wrong index which is being sent. 这将帮助您跟踪发送的错误索引。

感谢@mayur,他的评论才是正确的答案,“我之前在Objective-C中使用数组遇到了类似的错误……我的建议是将self与NSMutableArrays或NSArrays一起使用”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM