2017-08-09 70 views
0

Crazylytics發生了崩潰。com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS(來自iOS 8.x的NSTimer中)

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 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我沒有看到這個項目的任何[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];。剛纔我補充說,但是,我想確認是因爲多個addObserverNSTimer初始化而發生崩潰?

更新16/08/2017:

得到這個錯誤夫婦的時間和相同的兩個IOS版本8.x的

IOS版本:8.4.1(12H321)

型號:iPhone 5c(型號A1456,A1532)

更新17/08/2017:

第一次車禍發生在3個多月前,第二次車禍發生超過2周。在Xcode-organizer崩潰選項卡中無法獲取崩潰詳細信息。我只看到Crashlytics,而不是在Xcode-organizer。我無法理解Crashlytics崩潰細節比較Xcode-organizer

+0

您添加此BecomeActive obeserver?在上面的問題中提到的'HomeViewController'' viewWillAppear'中提到了觀察者初始化代碼中的 – CodeChanger

+0

。 – user3589771

+0

是否有任何其他viewController在你的應用程序或你只是在家庭ViewController和得到這個崩潰? – CodeChanger

回答

0

你不能把觀察者碼在viewWillAppear中,因爲代碼調用毀傷時間:

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