为什么我的程序从最近的应用程序栏删除后重新启动时会崩溃?
我是一个编程新手,如果这显示了我的无知,我很抱歉...
情况 1:
- 我的程序正在模拟器中运行。我按下主页按钮,然后再次按下程序的图标,它就会回到原来的位置。这是显而易见的——它被 iPhone 的多任务系统冻结了。
情况2:
- 我的程序正在模拟器中运行。我按下主页按钮,但这一次我双击该程序并将其从最近的应用程序栏中删除。然后我按该程序的图标再次启动它。
在情况 2 中,我希望我的程序只是从头开始加载,但相反,它会返回到崩溃之前短暂“冻结”的页面。
这是为什么呢?
编辑 - 这是崩溃的回溯。从您看到的第一个屏幕开始,我已经完全干净地安装了我的应用程序,没有任何数据,以将变量保持在最低限度:
#0 0x96dc009a in mach_msg_trap ()
#1 0x96dc0807 in mach_msg ()
#2 0x0111cd86 in __CFRunLoopServiceMachPort ()
#3 0x01079e74 in __CFRunLoopRun ()
#4 0x01079840 in CFRunLoopRunSpecific ()
#5 0x01079761 in CFRunLoopRunInMode ()
#6 0x01c821c4 in GSEventRunModal ()
#7 0x01c82289 in GSEventRun ()
#8 0x001c4c93 in UIApplicationMain ()
#9 0x00002429 in main (argc=1, argv=0xbffff050) at main.m:14
I'm a bit of a programming newbie so sorry if this shows my ignorance...
Situation 1:
- My program is running in the simulator. I press the home button, and then my program's icon again, and it goes back to exactly where it was. This much is obvious - it's been frozen by the iPhone's multitasking system.
Situation 2:
- My program is running in the simulator. I press the home button, but this time I then double-click the program and delete it from the recent-apps bar. Then I press the program's icon to start it again.
In situation 2, I expect my program just to load from the beginning, but instead, it goes back to the page it was 'frozen' on, briefly, before crashing.
Why is this?
EDIT - here is the backtrace of the crash. I've done it with a completely clean install of my app with no data, from the first screen you see, to keep variables to a minimum:
#0 0x96dc009a in mach_msg_trap ()
#1 0x96dc0807 in mach_msg ()
#2 0x0111cd86 in __CFRunLoopServiceMachPort ()
#3 0x01079e74 in __CFRunLoopRun ()
#4 0x01079840 in CFRunLoopRunSpecific ()
#5 0x01079761 in CFRunLoopRunInMode ()
#6 0x01c821c4 in GSEventRunModal ()
#7 0x01c82289 in GSEventRun ()
#8 0x001c4c93 in UIApplicationMain ()
#9 0x00002429 in main (argc=1, argv=0xbffff050) at main.m:14
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从评论中复制,因为这个理论似乎是正确的:Are you running through the Xcode debugger?可能是当您终止应用程序时,调试器会阻止进程被完全破坏,从而导致后续启动时崩溃。显然,如果您最初从模拟器而不是通过 Xcode 的调试器启动应用程序,它可以正常工作。
Copied from comment because this theory appears to have been correct: Are you running through the Xcode debugger? It could be that when you kill the app, the debugger sort of prevents the process from being completely destroyed, causing the crash on the subsequent launch. Apparently it work correctly if you initially launch the app from the simulator instead of via Xcode's debugger.
当您的应用从应用切换器终止时,它会调用应用委托的
applicationDidEnterBackground:(UIApplication *)application
方法。在这里您应该保存所有应用程序状态 - 您的应用程序使用的所有内存都将被释放。可能发生的情况是您的applicationDidEnterBackground:
方法中的某些内容崩溃了,或者对象模型的大规模释放中的某些内容导致了崩溃。编辑:
我刚刚重读了您的问题,发现它在重新启动时崩溃。对不起。您还应该检查
application:didFinishLaunchingWithOptions:
是否发生崩溃,因为应用程序首次启动时会调用该崩溃。尽管由于您看到的是应用程序关闭之前的最后一个屏幕,但崩溃似乎仍然可能与终止有关。如何获取回溯:
如果您在 Xcode 中打开调试的情况下在模拟器中运行代码并重现此崩溃,您应该能够发现哪一行崩溃了。当调试器发现崩溃并且 gdb 打开时(您应该在 Xcode 中看到
(gdb)
提示符),输入bt
并按 Enter 键以查看碰撞。将其粘贴到此处。查看 UIApplicationDelegate 的文档有关
applicationWillTerminate:
的更多信息。When your app is terminated from the App Switcher, it calls your app delegate's
applicationDidEnterBackground:(UIApplication *)application
method. Here you should save all application state–all of the memory your app uses will be released. What's likely happening is either that something in yourapplicationDidEnterBackground:
method is crashing or something in the mass deallocating of your object model is causing a crash.edit:
I just reread your question and saw that it's crashing on relaunch. Sorry. You should also check
application:didFinishLaunchingWithOptions:
for a crash, as that is called when your app first starts. Although since you're seeing the last screen before the app was closed, the crash still seems like it may be tied to terminatation.How to get a backtrace:
If you run the code in the simulator with debugging on in Xcode and reproduce this crash, you should be able to discover which line is crashing. When the debugger picks up on the crash and gdb turns on (you should see a
(gdb)
prompt in Xcode), typebt
and press enter to see the backtrace of the crash. Paste it here.See the docs of UIApplicationDelegate for more info on
applicationWillTerminate:
.我有同样的问题。由于某种原因,模拟器阻止我们杀死正在测试的应用程序。
我为测试所做的一件事是创建一个虚拟项目
如果您从另一个虚拟项目启动模拟器。
然后我可以在我的原始项目中打开/关闭/终止测试通知等。
I had same problem. For some reason the simulator prevents us to kill the app we are testing.
One thing I did for testing was to create a dummy project to
If you launch the simulator from another dummy project.
Then I could open/close/kill test notifications, etc in my original project.
拔掉电话线,是的。 GDB(调试器)是导致此问题的原因。
Unplug the phone, yes. GDB, the debugger, is the cause of this issue.