I have an asynchronous server request in my iOS app:
[self performSelectorInBackground:@selector(doSomething) withObject:nil];
How can I detect the end of this operation?
Put a call at the end of the doSomething method?!
- (void)doSomething {
// Thread starts here
// Do something
// Thread ends here
[self performSelectorOnMainThread:@selector(doSomethingDone) withObject:nil waitUntilDone:NO];
}
If you just want to know when it's finished (and don't want to pass much data back - at which point I would recommend a delegate) you could simply post a notification to the notification center.
[[NSNotificationCenter defaultCenter] postNotificationName:kYourFinishedNotificationName object:nil];
within your view controllers viewDidLoad method add:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yourNotificationListenerMethod:)
name:kYourFinishedNotificationName
object:nil];
and within dealloc, add:
[[NSNotificationCenter defaultCenter] removeObserver:self];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With