我无法理解崩溃。

时间:2016-05-02 14:39:37

标签: ios crash block weak

我遇到了崩溃的崩溃。可能它与weakSelf有关。

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)

和代码

//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];
    });
 }
}

1 个答案:

答案 0 :(得分:0)

对于已发布的版本,您可以看到崩溃和代码行,

xCode中的

:Window-> Organizer->崩溃

并从左侧面板中选择应用和版本

尝试“异常断点”

异常断点自动将断点添加到行导致崩溃,您可以看到问题

添加异常断点:

xCode中的

: 顶部菜单 - >调试 - >断点 - >创建异常断点...

再次运行

相关问题