From 560b37751274804c708afc8abb92cd2746db18c9 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 26 Oct 2016 14:17:44 -0400 Subject: [PATCH] Fix intermittent crash on network status change These notifications are posted off the main thread, so let's make sure we're only touching the view hierarchy on the main thread. // FREEBIE --- .../SignalsNavigationController.m | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Signal/src/view controllers/SignalsNavigationController.m b/Signal/src/view controllers/SignalsNavigationController.m index 17003817a..69da006eb 100644 --- a/Signal/src/view controllers/SignalsNavigationController.m +++ b/Signal/src/view controllers/SignalsNavigationController.m @@ -62,32 +62,38 @@ static double const STALLED_PROGRESS = 0.9; } - (void)socketDidOpen { - [_updateStatusTimer invalidate]; - for (UIView *view in self.navigationBar.subviews) { - if ([view isKindOfClass:[UIProgressView class]]) { - [view removeFromSuperview]; - _socketStatusView = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + [_updateStatusTimer invalidate]; + for (UIView *view in self.navigationBar.subviews) { + if ([view isKindOfClass:[UIProgressView class]]) { + [view removeFromSuperview]; + _socketStatusView = nil; + } } - } + }); } - (void)socketDidClose { - if (_socketStatusView == nil) { - [self initializeSocketStatusBar]; - _updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 - target:self - selector:@selector(updateSocketConnecting) - userInfo:nil - repeats:YES]; - - } else if (_socketStatusView.progress >= STALLED_PROGRESS) { - [_updateStatusTimer invalidate]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + if (_socketStatusView == nil) { + [self initializeSocketStatusBar]; + _updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 + target:self + selector:@selector(updateSocketConnecting) + userInfo:nil + repeats:YES]; + + } else if (_socketStatusView.progress >= STALLED_PROGRESS) { + [_updateStatusTimer invalidate]; + } + }); } - (void)updateSocketConnecting { - double progress = _socketStatusView.progress + 0.05; - _socketStatusView.progress = (float)MIN(progress, STALLED_PROGRESS); + dispatch_async(dispatch_get_main_queue(), ^{ + double progress = _socketStatusView.progress + 0.05; + _socketStatusView.progress = (float)MIN(progress, STALLED_PROGRESS); + }); } - (void)socketIsConnecting {