进入前台时应用程序崩溃

Posted

技术标签:

【中文标题】进入前台时应用程序崩溃【英文标题】:App crash while enter foreground 【发布时间】:2013-12-20 13:10:53 【问题描述】:

我的应用程序在进入前台时崩溃了两次。我努力模拟,但我不能。我也附上了崩溃日志。我无法从这个日志中得到原因。帮助我解决这个问题。提前致谢。

Incident Identifier: 644DF722-CCB1-4A62-9802-43AAE8FD7998
CrashReporter Key:   a78f95d5bb2b0cb796602919073666aa96af75e4
Hardware Model:      iPhone5,1
Process:             myapp [1611]
Path:                /var/mobile/Applications/5123A551-8D9B-4890-89B9-10AF4A84FDDF/myapp.app/myapp
Identifier:          com.myapp.iphone.myappequ
Version:             6.0 (6.0)
Code Type:           ARM (Native)
Parent Process:      launchd [1]

Date/Time:           2013-12-19 16:36:10.710 -0600
OS Version:          ios 7.0.4 (11B554a)
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                  0x2e65fe7e __exceptionPreprocess + 126
1   libobjc.A.dylib                 0x389bc6c2 objc_exception_throw + 34
2   CoreFoundation                  0x2e595ff4 -[__NSArrayI objectAtIndex:] + 172
3   myapp                           0x0010a4f2 0xee000 + 115954
4   UIKit                           0x30de8956 -[UIViewController loadViewIfRequired] + 514
5   UIKit                           0x30de8714 -[UIViewController view] + 20
6   UIKit                           0x30e60588 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 384
7   UIKit                           0x30e5eeec -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 1196
8   UIKit                           0x30e5ea32 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 42
9   UIKit                           0x30e5e9ba -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 90
10  UIKit                           0x30e5e952 -[UIWindow _setRotatableViewOrientation:duration:force:] + 38
11  UIKit                           0x30e57454 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 104
12  UIKit                           0x30dea392 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 378
13  UIKit                           0x30e5e6a4 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 692
14  UIKit                           0x30e5e178 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 156
15  UIKit                           0x30def57c -[UIWindow addRootViewControllerViewIfPossible] + 460
16  UIKit                           0x30decae0 -[UIWindow _setHidden:forced:] + 304
17  UIKit                           0x30e57828 -[UIWindow makeKeyAndVisible] + 56
18  myapp                           0xee000 + 22384
19  UIKit                           0x30e54aa8 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
20  UIKit                           0x30e544ee -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1386
21  UIKit                           0x30e4eb3c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 716
22  UIKit                           0x30de9a02 -[UIApplication handleEvent:withNewEvent:] + 3138
23  UIKit                           0x30de8cf8 -[UIApplication sendEvent:] + 68
24  myapp                           0x00153774 0xee000 + 415604
25  UIKit                           0x30e4e31c _UIApplicationHandleEvent + 660
26  GraphicsServices                0x332ce768 _PurpleEventCallback + 604
27  GraphicsServices                0x332ce352 PurpleEventCallback + 30
28  CoreFoundation                  0x2e62a772 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 30
29  CoreFoundation                  0x2e62a70e __CFRunLoopDoSource1 + 342
30  CoreFoundation                  0x2e628eda __CFRunLoopRun + 1402
31  CoreFoundation                  0x2e59346c CFRunLoopRunSpecific + 520
32  CoreFoundation                  0x2e59324e CFRunLoopRunInMode + 102
33  UIKit                           0x30e4d5be -[UIApplication _run] + 758
34  UIKit                           0x30e48840 UIApplicationMain + 1132
35  myapp                           0x000f3136 0xee000 + 20790
36  myapp                           0xee000 + 20668


Thread 0 Crashed:
0   libsystem_kernel.dylib          0x38f6c1fc __pthread_kill + 8
1   libsystem_pthread.dylib         0x38fd3a4e pthread_kill + 54
2   libsystem_c.dylib               0x38f1d028 abort + 72
3   libc++abi.dylib                 0x3836b98a abort_message + 70
4   libc++abi.dylib                 0x383846e2 default_terminate_handler() + 250
5   libobjc.A.dylib                 0x389bc936 _objc_terminate() + 190
6   libc++abi.dylib                 0x383821b0 std::__terminate(void (*)()) + 76
7   libc++abi.dylib                 0x38381d12 __cxa_rethrow + 98
8   libobjc.A.dylib                 0x389bc80a objc_exception_rethrow + 38
9   CoreFoundation                  0x2e5934e2 CFRunLoopRunSpecific + 638
10  CoreFoundation                  0x2e59324e CFRunLoopRunInMode + 102
11  UIKit                           0x30e4d5be -[UIApplication _run] + 758
12  UIKit                           0x30e48840 UIApplicationMain + 1132
13  myapp                           0x000f3136 0xee000 + 20790
14  myapp                           0x000f30bc 0xee000 + 20668

Thread 1:
0   libsystem_kernel.dylib          0x38f59838 kevent64 + 24
1   libdispatch.dylib               0x38ea80d0 _dispatch_mgr_invoke + 228
2   libdispatch.dylib               0x38ea261e _dispatch_mgr_thread + 34

Thread 2:
0   libsystem_kernel.dylib          0x38f6cc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x38fd0e06 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x38fd0cc0 start_wqthread + 4

Thread 3:
0   libsystem_kernel.dylib          0x38f6cc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x38fd0e06 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x38fd0cc0 start_wqthread + 4

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x00000000    r1: 0x00000000      r2: 0x00000000      r3: 0x00002060
    r4: 0x00000006    r5: 0x3ad9918c      r6: 0x00000000      r7: 0x27d15594
    r8: 0x14d8cfd0    r9: 0x00000001     r10: 0x14e50ea0     r11: 0x14e8c7a0
    ip: 0x00000148    sp: 0x27d15588      lr: 0x38fd3a53      pc: 0x38f6c1fc
  cpsr: 0x00000010

applicationWillEnterForeground 中的代码

- (void)applicationWillEnterForeground:(UIApplication *)application

    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
    [application endBackgroundTask:self.bgTaskId];
    self.bgTaskId = UIBackgroundTaskInvalid;


【问题讨论】:

【参考方案1】:

问题不在您的 AppDelegate 代码中,可能在加载的 UIViewController 中,可能在 viewDidLoad 中。正如您在第 3 行看到的那样,崩溃没有完全符号化:“myapp”应该显示来自您的代码的对象和消息。

如需更全面的答案,请从应用启动屏幕上显示的UIViewController 中发布您的viewDidLoad 代码。

【讨论】:

+1 供您参考。实际上我无法重现崩溃。在崩溃时我没有注意到正在加载的视图控制器。谢谢,我会检查的。【参考方案2】:

检查您的loadView 和/或viewDidLoad(因为这是iOS 的loadViewIfRequired 调用)中访问NSArray 中的对象的语句。

还可以看看here,类似的堆栈跟踪顶部。

【讨论】:

【参考方案3】:

看起来当应用程序进入前台时,您正在尝试从 NSArray 访问数据,而这些数据在应用程序进入后台时会失效。尝试注册

//in viewWillAppear
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAppComingToForeground)name:UIApplicationWillEnterForegroundNotification object:nil];

//in viewWillDisapear
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];

在 handleAppComingToForeground 方法中,您可以重新初始化您的数组的数据。

同样,您可以为 UIApplicationDidEnterBackgroundNotification 设置观察者,并在应用程序进入后台时存储视图控制器级别的数据。

【讨论】:

以上是关于进入前台时应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章

调用前台服务时应用程序崩溃[重复]

Android 应用在收到新的 FCM 消息时崩溃(前台和后台)

接收新的FCM消息(前台和后台)时Android应用程序崩溃

重新打开应用程序时出现 Moengage 问题

应用进入前台时取消后台任务

当应用程序从后台进入前台时,MPMoviePlayerController 黑屏