简体   繁体   English

为什么我的应用程序即使在崩溃后也没有关闭

[英]Why my app is not closing even after a crash

I am working on an iPad app. 我正在开发一款iPad应用程序。 Sometimes it get crashed (I know the reason) but I am wondering why the app does not close even after a crash! 有时它会崩溃(我知道原因)但我想知道为什么应用程序即使在崩溃后也不会关闭! When the app crash I got some error related to crash in console but the app does not close. 当应用程序崩溃时,我得到了一些与控制台崩溃相关的错误,但应用程序没有关闭。 It even appear in the multitasking bar (I can see that when I press home button two times). 它甚至出现在多任务栏中(我可以看到,当我按下主页按钮两次)。 I am wondering is there some kind of setting for this? 我想知道这有什么设置吗? or this is a normal behavior? 或者这是正常的行为?

If you are running the App from Xcode, the debugger will still be attached so the crash will not terminate the process. 如果从Xcode运行应用程序,调试器仍将附加,因此崩溃不会终止进程。 You can use the Xcode debugger to take a look at the stack, inspect variables etc. Only when you stop the app in Xcode will the process be completely terminated. 您可以使用Xcode调试器来查看堆栈,检查变量等。只有当您在Xcode中停止应用程序时,该过程才会完全终止。

@Mike Weller is correct. @Mike Weller是对的。

It is typical behavior of the simulator to not close the app upon a crash as the debugger is designed to stop at the point of code where the crash occurs (for obvious reasons!). 模拟器的典型行为是在崩溃时不关闭应用程序,因为调试器被设计为在发生崩溃的代码点停止(出于显而易见的原因!)。

If you want to check it on device for your satisfaction. 如果您想在设备上查看它以满足您的需求。 Connect your device, run the app once on it via xcode. 连接您的设备,通过xcode运行应用程序一次。 Close app (stop on xcode). 关闭应用程序(停止在xcode上)。 Then disconnect the device. 然后断开设备。

The app will be now installed on your device like any other normal app. 该应用程序现在将像任何其他普通应用程序一样安装在您的设备上。 Run this app and do whatever causes it to crash. 运行此应用程序,并做任何导致它崩溃的事情。 You will see that the app will close and you will be thrown back to the iphone springboard screen. 您将看到该应用程序将关闭,您将被扔回iphone跳板屏幕。

As for app appearing in the multitasking bar, it has already been mentioned here that the presence of the app in the multitasking bar does not mean that it is still running. 对于出现在多任务栏中的应用程序,这里已经提到过,多任务栏中应用程序的存在并不意味着它仍然在运行。 This is vital difference in architectures between ios and android. 这是ios和android之间架构的重要区别。

The multitasking bar is NOT a task manager. 多任务栏不是任务管理器。 The ios philosophy is that the user does not need to know that an app is running or not. ios的理念是用户不需要知道应用程序是否正在运行。 He only needs to know which apps he has run in the past. 他只需要知道他过去运行过哪些应用程序。

The reason that it doesn't close, is probably that the app is actually not crashing. 它没有关闭的原因可能是应用程序实际上没有崩溃。

Could it be so that the print you are seeing is an Exception that is printed to the log? 可能是因为您看到的打印是打印到日志的异常吗? Could it be that you are catching this exception after it is printed? 可能是你在打印后遇到这个例外吗?

Like this: 像这样:

@try {
   [test characterAtIndex:6];
}
@catch (NSException * e) {
   NSLog(@"Exception: %@", e);
}

The above code would not crash, since the exception is caught. 上面的代码不会崩溃,因为异常被捕获。 Catching an exception is telling the platform that you took care of the problem so the app does not need to crash. 捕获异常会告诉平台您已解决问题,因此应用程序不需要崩溃。

There could be many other reasons, but with the info you provided this is my best guess. 可能还有很多其他原因,但是根据您提供的信息,这是我最好的猜测。 You could post the log print that you are seeing, that would certainly give a better clue... 您可以发布您正在看到的日志打印,这肯定会提供更好的线索......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM