Skip to content

Commit

Permalink
Merge pull request mrackwitz#58 from mrackwitz/fix/57_afnetworking_su…
Browse files Browse the repository at this point in the history
…pport_operation_finished

Fixes mrackwitz#57: Hides overlay if task/operation is finished
  • Loading branch information
mrackwitz committed Aug 20, 2014
2 parents 0f308ea + 25e2f83 commit e5f258d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Example/MRAFNetworkingSupportOperationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ - (IBAction)onOverlayViewGo:(id)sender {
}];

MRProgressOverlayView *overlayView = [MRProgressOverlayView showOverlayAddedTo:self.view animated:YES];
[overlayView setModeAndProgressWithStateOfOperation:operation];
[overlayView setStopBlockForOperation:operation];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// Do an expensive background operation, before observing the operation
sleep(2);

dispatch_async(dispatch_get_main_queue(), ^{
[overlayView setModeAndProgressWithStateOfOperation:operation];
[overlayView setStopBlockForOperation:operation];
});
});
}

- (IBAction)onOverlayViewUpload:(id)sender {
Expand Down
4 changes: 4 additions & 0 deletions src/Support/AFNetworking/MRProgressOverlayView+AFNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ - (void)setModeAndProgressWithStateOfTask:(NSURLSessionTask *)task {
[task addObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesSent)) options:0 context:MRTaskCountOfBytesSentContext];
[task addObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesReceived)) options:0 context:MRTaskCountOfBytesReceivedContext];
#pragma clang diagnostic pop
} else {
[self dismiss:YES];
}
}
}
Expand Down Expand Up @@ -151,6 +153,8 @@ - (void)setModeAndProgressWithStateOfOperation:(AFURLConnectionOperation *)opera
// Unregister
[weakSelf.operation setDownloadProgressBlock:originalDownloadProgressBlock];
}];
} else {
[self dismiss:YES];
}
}
}
Expand Down

0 comments on commit e5f258d

Please sign in to comment.