2016-05-02 2 views
0

J'ai eu un accident de crashlytics. Probablement lié à weakSelf.Je ne peux pas comprendre un accident.

Crashed: com.apple.main-thread 
EXC_BREAKPOINT 0x000000000defe 

0 libobjc.A.dylib    0x224aea44 _objc_trap() 
1 libobjc.A.dylib    0x224aeaa9 _objc_inform + 70 
2 libobjc.A.dylib    0x224c8413 weak_register_no_lock + 210 
3 libobjc.A.dylib    0x224c8993 objc_initWeak + 130 
4 GPS_______appLite    0xd77b1 -[ModuleView observeValueForKeyPath:ofObject:change:context:] (ModuleView.m:232) 
5 GPS_______appLite    0xd9287 -[ModuleSpeedometerView observeValueForKeyPath:ofObject:change:context:] (ModuleSpeedometerView.m:198) 
6 Foundation      0x2349aa91 NSKVONotify + 52 
7 Foundation      0x23479bef NSKeyValueNotifyObserver + 286 
8 Foundation      0x23479847 NSKeyValueDidChange + 346 
9 Foundation      0x23466599 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 96 
10 GPS_______appLite    0x12c393 -[GPSTracker private_updateCurrentStatisticsWithLocation:] (GPSTracker.mm:1887) 
11 GPS_______appLite    0x12c1b9 -[GPSTracker private_addLocationToHistory:] (GPSTracker.mm:1870) 
12 GPS_______appLite    0x12c6af -[GPSTracker private_processNewLocation:fromManager:] (GPSTracker.mm:1938) 
13 GPS_______appLite    0x12c88b -[GPSTracker locationManager:didUpdateLocations:] (GPSTracker.mm:1953) 
14 CoreLocation     0x28c5c493 (null) + 25830 
15 CoreLocation     0x28c5765b (null) + 5806 
16 CoreLocation     0x28c50725 (null) + 988 
17 CoreFoundation     0x22cd5d91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 
18 CoreFoundation     0x22cd584d __CFRunLoopDoBlocks + 216 
19 CoreFoundation     0x22cd41bf __CFRunLoopRun + 1806 
20 CoreFoundation     0x22c232e9 CFRunLoopRunSpecific + 520 
21 CoreFoundation     0x22c230d5 CFRunLoopRunInMode + 108 
22 GraphicsServices    0x24213ac9 GSEventRunModal + 160 
23 UIKit       0x272e80b9 UIApplicationMain + 144 
24 GPS_______appLite    0x10adc7 main (main.m:15) 
25 libdispatch.dylib    0x228cb873 (Missing) 

et le code

//ModuleView class 
- (void)observeValueForKeyPath:(NSString *)keyPath 
        ofObject:(id)object 
        change:(NSDictionary *)change 
        context:(void *)context 
{ 
if ([object isKindOfClass:[GPSTracker class]]) 
{ 
    __weak GPSTracker *tracker = (GPSTracker *)object; 
    __weak __typeof__(self) weakSelf = self; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     if ([keyPath isEqualToString:NSStringFromSelector(@selector(trackerMode))]) 
     { 
      [weakSelf trackerStateChanged]; 
     } 
     else if ([keyPath isEqualToString:NSStringFromSelector(@selector(currentStatistics))]) 
     { 
      id oldValue = [change objectForKey:NSKeyValueChangeOldKey]; 
      if (!oldValue 
       || [oldValue isKindOfClass:[NSNull class]]) 
      { 
       // If statistics instance has been initialized 
       if (!weakSelf.shouldIgnoreUpdates) 
       { 
        [tracker.currentStatistics.time addUniqueObserver:weakSelf 
                  forKeyPath:NSStringFromSelector(@selector(elapsed)) 
                   options:NSKeyValueObservingOptionNew]; 
       } 
      } 

      [weakSelf trackerUpdate]; 
     } 
    }); 
} 
else if ([object isKindOfClass:[GPSTrackerTimeStatistics class]]) 
{ 
    __weak __typeof__(self) weakSelf = self; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [weakSelf timerUpdate]; 
    }); 
} 
} 
+0

Indiquez la ligne de code de la ligne 232 de ModuleView.m. – rmaddy

+0

rmaddy, __ faible __typeof __ (auto-) faibleSelf = self; – Voloda2

+0

Je ne connais pas le crash, mais vous n'avez pas besoin d'utiliser '__weak Self' ici, parce que vous n'avez pas de cycle de retenue. Votre ModuleView n'a pas de pointeur fort vers le bloc, donc vous pouvez passer en toute sécurité 'self' dans le bloc au lieu de' weakSelf'. – dirkgroten

Répondre

0

pour la version publiée, vous pouvez voir les accidents et la ligne de code,

dans Xcode: Window-> Organizer-> tombe en panne

et application et sélectionnez version à partir des panneaux de gauche

"Exception Breakpoint"

Exception Breakpoint ajouter automatiquement breakpoint à la ligne a provoquer l'accident, et vous pouvez voir le problème

pour ajouter Exception Breakpoint:

dans Xcode: menu du haut -> Debug -> Points d'arrêt -> Créer une exception Breakpoint Et recommencez