应用程序崩溃,没有异常或崩溃日志
我的应用程序崩溃了,但在控制台中没有生成任何异常,并且设备上没有崩溃日志。没有收到内存警告。有什么方法可以缩小原因而不必注释掉代码吗?
My app crashes, but generates no exception in the console and no crash log on the device. No memory warnings are received. Is there any way I can narrow down the cause without having to comment out code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单步执行代码应该可以帮助您确定应用程序崩溃的位置,这将在程序遇到任何“坏”代码之前停止执行(前提是您放置断点 - 代码将在正确的位置停止)。您可以通过单击代码编辑窗格左侧的相应行号来添加断点,并可以通过“视图”->“导航器”->“显示断点导航器”菜单访问断点管理器。
您可能对当前正在执行的方法或类有一些了解,在这种情况下,您应该在该方法的第一行放置一个断点,如果该类是 UIViewController 则将断点放在它的第一行 -( void)viewDidLoad 方法可能会有所帮助。您可以按一下将断点放在应用程序委托中 -(void)applicationDidFinishLaunching 的第一行。然而,这将需要大量单步执行指令,而不仅仅是单步执行指令。
https://developer.apple.com/ Library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/Debugging/Debugging.html
苹果还建议打开静态分析器,然后推断问题你的代码来自它的输出。
Stepping through the code should help you nail down where the app is crashing, this will stop the program execution before it hits any "bad" code (providing you put the breakpoint - where the code will stop in the right place). You can add a break point by clicking on the appropriate line number to the left of the code editing pane and can access the break points organiser through the View->Navigators->Show Breakpoint Navigators menu.
You may have some inkling of the method or class that's currently being executed in which case you should put a break point on the first line of that method, if the class is a UIViewController then putting the break point on the first line of it's -(void)viewDidLoad method may help. You could, at a push, put your breakpoint on the first line of -(void)applicationDidFinishLaunching in the application delegate. However this will require a lot of stepping into instructions rather than just stepping over instructions.
https://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/Debugging/Debugging.html
Apple also suggest turning on the static analyser and then inferring problems in your code from it's output.
崩溃的原因是我正在使用 NSLog 记录一个非常大的数组 - 不知道这可能会导致应用程序崩溃!
The reason for the crash was that I was logging a really large array with NSLog - did not know that could crash an app!