Apple Review拒绝NSBundle例外



我试图在应用商店发布应用程序,但我得到了苹果团队的回应,应用程序崩溃了。我使用Crashlytics,所以我得到了特定的崩溃线。我无法在设备或模拟器中复制崩溃。

这段代码应该计算静态资源的md5总和,以确保没有人更改它们。

代码:

NSArray *formats = @[@"html", @"mustache", @"strings", @"p12", @"xml", @"der", @"nss", @"css", @"json", @"plist"];
NSArray *filesToSkip = @[@"Info.plist"];
NSBundle *bundle = [NSBundle mainBundle];
NSString *resourcePath = [bundle resourcePath];
NSFileManager *man = [NSFileManager defaultManager];
NSArray *resPaths = [man subpathsAtPath:resourcePath];
resPaths = [resPaths sortedArrayUsingSelector:@selector(compare:)];
NSMutableArray *sums = [NSMutableArray array];
for(NSString *path in resPaths) {
    if([filesToSkip containsObject:[path lastPathComponent]] == NO && [formats containsObject:[path pathExtension]]) {
        NSString *fullPath = [resourcePath stringByAppendingPathComponent:path];
        NSData *content = [NSData dataWithContentsOfFile:fullPath];
        NSString *md5 = [content md5];
        [sums addObject:md5]; //line of crash - inserting nil element into the NSMutableArray
    }
}

md5方法,如果从这里开始:https://stackoverflow.com/a/16391701/5226328—当NSData对象为nil时,返回nil。

它试图找到问题,但我不知道发生了什么:

我找不到任何能使md5(字符串)为nil的场景(即使bundle==nil或resourcePath==nil也不应该在那一行崩溃)。

我想我错过了什么(或者不理解Apple Review的方法)。如有任何帮助或建议,我们将不胜感激。

不能使用addObject方法将nil添加到NSMutableArray中。或者,只要MD5方法返回nil,就可以尝试将[NSNull-null]添加到数组中。稍后在代码中,当您使用NSMutableArray时,还需要检查NSNull对象,并将其解释为nil。

这里有一个类似的帖子:如何将nil添加到nsmutalearray?

最新更新