在iOS9中,我的应用程序SWPi在main.m中崩溃:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = 0;
@try
{ NSLog(@"MAIN:");
retVal = UIApplicationMain(argc, argv, nil, nil);
}
@catch (NSException *exception)
{ NSLog(@"CRASH: %@", exception);
NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
}
@finally
{ [pool release];
}
return retVal;
}
迹:
2015-09-19 12:31:57.197 SWPi[441:79241] MAIN:
2015-09-19 12:31:57.533 SWPi[441:79241] CRASH: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
2015-09-19 12:31:57.550 SWPi[441:79241] Stack Trace: (
0 CoreFoundation 0x22de96a3 <redacted> + 150
1 libobjc.A.dylib 0x34762e17 objc_exception_throw + 38
2 Foundation 0x23b69903 <redacted> + 110
3 Foundation 0x23b69abf <redacted> + 442
4 Foundation 0x23b3c9c9 <redacted> + 3764
5 Foundation 0x23b3ba6d <redacted> + 276
6 UIKit 0x27332f57 <redacted> + 1110
7 UIKit 0x27334f1d <redacted> + 196
8 UIKit 0x27143d19 <redacted> + 48
9 UIKit 0x26f1f34d <redacted> + 260
10 UIKit 0x27142d61 <redacted> + 1232
11 UIKit 0x27155db9 <redacted> + 36
12 UIKit 0x271403cf <redacted> + 134
13 FrontBoardServices 0x2ad82ccf <redacted> + 230
14 FrontBoardServices 0x2ad82fc1 <redacted> + 48
15 CoreFoundation 0x22dacc3f <redacted> + 14
16 CoreFoundation 0x22dac82d <redacted> + 452
17 CoreFoundation 0x22daab9b <redacted> + 794
18 CoreFoundation 0x22cfe249 CFRunLoopRunSpecific + 520
19 CoreFoundation 0x22cfe035 CFRunLoopRunInMode + 108
20 UIKit 0x26f18b2d <redacted> + 524
21 UIKit 0x26f138a9 UIApplicationMain + 144
22 SWPi 0x00015f6f main + 182
23 libdyld.dylib 0x34eae873 <redacted> + 2
)
在iOS8下,一切都是对的。 哪里可能有问题?
为所有异常插入断点后调试:
2015-09-19 13:35:16.322 SWPi[454:85641] MAIN:
(lldb) bt
* thread #1: tid = 0x14e89, 0x34762df0 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x34762df0 libobjc.A.dylib`objc_exception_throw
frame #1: 0x22d03d7e CoreFoundation`-[__NSArrayM insertObject:atIndex:] + 622
frame #2: 0x26fe40d4 UIKit`-[UINavigationController _navigationItems] + 240
frame #3: 0x272181e6 UIKit`-[UINavigationController initWithCoder:] + 886
frame #4: 0x23b3c630 Foundation`_decodeObjectBinary + 2844
frame #5: 0x23b3ba6c Foundation`_decodeObject + 276
frame #6: 0x271ba5cc UIKit`-[UINavigationBar initWithCoder:] + 404
frame #7: 0x23b3c630 Foundation`_decodeObjectBinary + 2844
frame #8: 0x23b3ba6c Foundation`_decodeObject + 276
frame #9: 0x271b6bfe UIKit`-[UINavigationItem initWithCoder:] + 734
frame #10: 0x23b3c630 Foundation`_decodeObjectBinary + 2844
frame #11: 0x23b3ba6c Foundation`_decodeObject + 276
frame #12: 0x271fa904 UIKit`-[UIViewController initWithCoder:] + 460
frame #13: 0x27333ce2 UIKit`-[UIClassSwapper initWithCoder:] + 218
frame #14: 0x23b3c630 Foundation`_decodeObjectBinary + 2844
frame #15: 0x23b3ba6c Foundation`_decodeObject + 276
frame #16: 0x273339f0 UIKit`-[UIRuntimeConnection initWithCoder:] + 160
frame #17: 0x2733404c UIKit`-[UIRuntimeEventConnection initWithCoder:] + 52
frame #18: 0x23b3c630 Foundation`_decodeObjectBinary + 2844
frame #19: 0x23b427d2 Foundation`-[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1378
frame #20: 0x23adf2da Foundation`-[NSArray(NSArray) initWithCoder:] + 318
frame #21: 0x23b3c630 Foundation`_decodeObjectBinary + 2844
frame #22: 0x23b3ba6c Foundation`_decodeObject + 276
frame #23: 0x27332f56 UIKit`-[UINib instantiateWithOwner:options:] + 1110
frame #24: 0x27334f1c UIKit`-[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 196
frame #25: 0x27143d18 UIKit`-[UIApplication _loadMainNibFileNamed:bundle:] + 48
frame #26: 0x26f1f34c UIKit`-[UIApplication _loadMainInterfaceFile] + 260
frame #27: 0x27142d60 UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1232
frame #28: 0x27155db8 UIKit`__84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3181 + 36
frame #29: 0x271403ce UIKit`-[UIApplication workspaceDidEndTransaction:] + 134
frame #30: 0x2ad82cce FrontBoardServices`-[FBSSerialQueue _performNext] + 230
frame #31: 0x2ad82fc0 FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 48
frame #32: 0x22dacc3e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
frame #33: 0x22dac82c CoreFoundation`__CFRunLoopDoSources0 + 452
frame #34: 0x22daab9a CoreFoundation`__CFRunLoopRun + 794
frame #35: 0x22cfe248 CoreFoundation`CFRunLoopRunSpecific + 520
frame #36: 0x22cfe034 CoreFoundation`CFRunLoopRunInMode + 108
frame #37: 0x26f18b2c UIKit`-[UIApplication _run] + 524
frame #38: 0x26f138a8 UIKit`UIApplicationMain + 144
* frame #39: 0x00074f8e SWPi`main(argc=1, argv=0x00920b54) + 182 at main.m:7
*编辑
麻烦在于主xib。 iOS4-8忽略它,iOS9没有。
在文字模式下:
<navigationItem key="navigationItem" title="Item" id="R9S-B3-9Aq"/>
此项目在父控制器的Outlets中的Xcode中可见,但在文本模式下的xib中没有插座引用。 在Xcode中,这个插座与其他插座一样是灰色的,我无法将其删除。 在文本模式下删除xib的这一行,并且出口&amp;父母的引用* .m&amp; * .h app正常运行。
答案 0 :(得分:1)
正如其他人所说的那样,您正在将nil对象插入代码中的某个数组中。调试器不是很好地报告发生错误的源代码行。它可能表明它在main.m中,但这显然是错误的。
尝试在所有Objective-C异常上设置全局断点。这通常会导致Xcode向您显示导致崩溃的实际行。 (不需要在main.m中使用try / catch,它甚至可能会混淆。)
好的,我想我看到你在答案中改变了什么。您添加了第二个堆栈跟踪。
您的崩溃日志是否仍然声称在main.m中发生了错误?从第二个崩溃日志开始,打开初始视图控制器的视图控制器场景可能会出现问题。有一个对_runWithMainScene的引用:transitionContext:堆栈跟踪中的完成,然后是-[UIApplication _loadMainNibFileNamed:bundle:]
(内部故事板实际上包含nib文件。
我的猜测是你的故事板中的根视图控制器中存在一些微妙的损坏。还有一个-[UINavigationController _navigationItems]
的电话。这表明根视图控制器中的导航项可能存在问题。
我认为您的应用使用导航控制器作为根视图控制器?