【问题标题】:Apple Review refuses NSBundle exceptionApple Review 拒绝 NSBundle 例外
【发布时间】:2016-05-18 09:28:02
【问题描述】:

我尝试在 App Store 中发布应用程序,但我收到了 Apple 团队的回复,该应用程序崩溃了。我使用 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 (string) nil 的场景(即使使用 bundle == nil 或 resourcePath == nil 它也不应该在该行崩溃)。

我想我错过了一些东西(或者不了解 Apple Review 方法)。任何帮助或建议将不胜感激。

【问题讨论】:

    标签: ios objective-c md5


    【解决方案1】:

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

    这是一个类似的帖子:how to add nil to nsmutablearray?

    【讨论】:

    • 感谢您的回答。我知道我不能将 nil 添加到 NSMutableArray。但是提供的代码不应该尝试这个。要添加 nil resurcePathpath 必须为 nil - 但不会执行 for-in。另一种可能性 - fullPath 不指向任何文件。但这也不太可能 - 路径是在几行之前获得的。我知道它不能为零。但我不知道它怎么可能是零。
    猜你喜欢
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多