【问题标题】:com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS (at NSTimer from iOS 8.x)com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS(在 iOS 8.x 的 NSTimer 上)
【发布时间】:2017-08-09 05:47:21
【问题描述】:

由于 crashlytics 导致崩溃。

Crashed: com.apple.main-thread

0  libobjc.A.dylib                0x197e37bdc objc_msgSend + 28
1  Foundation                     0x1881192c8 -[NSCFTimer initWithFireDate:interval:target:selector:userInfo:repeats:] + 140
2  Foundation                     0x188123d3c +[NSTimer(NSTimer) scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:] + 140
3  RV PetSafety                   0x1000fd2a0 -[HomeViewController UIApplicationDidBecomeActive:] (HomeViewController.m:179)
4  CoreFoundation                 0x1872dc1e0 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
5  CoreFoundation                 0x18721b370 _CFXNotificationPost + 2060
6  Foundation                     0x188116cc0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
7  UIKit                          0x18bb664c0 -[UIApplication _stopDeactivatingForReason:] + 464
8  UIKit                          0x18bd77818 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:] + 2664
9  FrontBoardServices             0x18f56d640 __31-[FBSSerialQueue performAsync:]_block_invoke + 28
10 CoreFoundation                 0x1872ee124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
11 CoreFoundation                 0x1872ed22c __CFRunLoopDoBlocks + 312
12 CoreFoundation                 0x1872eb850 __CFRunLoopRun + 1756
13 CoreFoundation                 0x1872191f4 CFRunLoopRunSpecific + 396
14 GraphicsServices               0x1903835a4 GSEventRunModal + 168
15 UIKit                          0x18bb4a784 UIApplicationMain + 1488
16 RV PetSafety                   0x1001161e8 main (main.m:14)
17 libdyld.dylib                  0x198492a08 start + 4

我的代码在哪里:

- (void)UIApplicationDidBecomeActive:(NSNotification *)notification {
    if([updateTimer isValid]) {
        [updateTimer invalidate];
    }
    updateTimer = [NSTimer scheduledTimerWithTimeInterval:refreshInterval
                                                   target:self
                                                 selector:@selector(refreshData)
                                                 userInfo:nil
                                                  repeats:YES];
}

每当我的应用程序激活时,我都想更新我的NSTimer 时间。我需要调用 API 一段时间。我在这种方法上崩溃了。在上面的选择器方法refreshData 上具有 API 调用。在viewWillAppear初始化NSNotificationCenter

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UIApplicationDidBecomeActive:)
                                             name:UIApplicationDidBecomeActiveNotification object:nil];

Crashlytics 标题 HomeViewController.m line 179 -[HomeViewController UIApplicationDidBecomeActive:] 在该行

updateTimer = [NSTimer scheduledTimerWithTimeInterval:refreshInterval
                                                   target:self
                                                 selector:@selector(refreshData)
                                                 userInfo:nil
                                                  repeats:YES];

我在这个项目中没有看到任何[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];。刚才我添加了,但是,我想确认是因为多个addObserverNSTimer 初始化而发生崩溃?

2017 年 8 月 16 日更新:

两次都遇到这个错误,而且都是相同的 iOS 版本 8.x

iOS 版本:8.4.1 (12H321)

型号:iPhone 5c(型号 A1456、A1532)

2017 年 8 月 17 日更新:

第一次崩溃发生在 3 个多月前,第二次发生在 2 周多前。我无法在Xcode-organizer 崩溃选项卡中获取崩溃详细信息。我只在Crashlytics 中看到过其他一些崩溃,而不是在Xcode-organizer 中。我无法理解 CrashlyticsXcode-organizer 相比的崩溃细节

【问题讨论】:

  • 你在哪里添加了这个成为活跃的观察者?
  • at HomeViewController viewWillAppear 上面的观察者初始化代码中提到的问题。
  • 您的应用程序中是否还有其他 viewController 或者您只是在 Home ViewController 中并遇到此崩溃?
  • HomeViewController 仅适用于UIApplicationDidBecomeActiveNotification。我有一些其他带有自定义 observer 的视图控制器,直到现在我还没有从其他视图控制器中遇到任何崩溃。
  • @CodeChanger 检查今天的更新有问题:是不是因为Crashlytics努力得到每个crash

标签: ios objective-c nstimer nsnotificationcenter crashlytics


【解决方案1】:

您不能将观察者代码放在 viewWillAppear 中,因为该代码会调用 mutilate 时间:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(UIApplicationDidBecomeActive:)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:nil];

【讨论】:

    猜你喜欢
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 2015-12-18
    相关资源
    最近更新 更多