Skip to content

Commit 560b377

Browse files
committed
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
1 parent 66f0f8c commit 560b377

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

Signal/src/view controllers/SignalsNavigationController.m

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,38 @@ - (void)initializeObserver {
6262
}
6363

6464
- (void)socketDidOpen {
65-
[_updateStatusTimer invalidate];
66-
for (UIView *view in self.navigationBar.subviews) {
67-
if ([view isKindOfClass:[UIProgressView class]]) {
68-
[view removeFromSuperview];
69-
_socketStatusView = nil;
65+
dispatch_async(dispatch_get_main_queue(), ^{
66+
[_updateStatusTimer invalidate];
67+
for (UIView *view in self.navigationBar.subviews) {
68+
if ([view isKindOfClass:[UIProgressView class]]) {
69+
[view removeFromSuperview];
70+
_socketStatusView = nil;
71+
}
7072
}
71-
}
73+
});
7274
}
7375

7476
- (void)socketDidClose {
75-
if (_socketStatusView == nil) {
76-
[self initializeSocketStatusBar];
77-
_updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
78-
target:self
79-
selector:@selector(updateSocketConnecting)
80-
userInfo:nil
81-
repeats:YES];
82-
83-
} else if (_socketStatusView.progress >= STALLED_PROGRESS) {
84-
[_updateStatusTimer invalidate];
85-
}
77+
dispatch_async(dispatch_get_main_queue(), ^{
78+
if (_socketStatusView == nil) {
79+
[self initializeSocketStatusBar];
80+
_updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
81+
target:self
82+
selector:@selector(updateSocketConnecting)
83+
userInfo:nil
84+
repeats:YES];
85+
86+
} else if (_socketStatusView.progress >= STALLED_PROGRESS) {
87+
[_updateStatusTimer invalidate];
88+
}
89+
});
8690
}
8791

8892
- (void)updateSocketConnecting {
89-
double progress = _socketStatusView.progress + 0.05;
90-
_socketStatusView.progress = (float)MIN(progress, STALLED_PROGRESS);
93+
dispatch_async(dispatch_get_main_queue(), ^{
94+
double progress = _socketStatusView.progress + 0.05;
95+
_socketStatusView.progress = (float)MIN(progress, STALLED_PROGRESS);
96+
});
9197
}
9298

9399
- (void)socketIsConnecting {

0 commit comments

Comments
 (0)