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
pull/1/head
Michael Kirk 9 years ago
parent 66f0f8cc95
commit 560b377512

@ -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 {

Loading…
Cancel
Save