I started the delayed stream using performSelector , but the user still has the ability to click the back button on the current view, which calls dealloc. When this happens, my stream still seems to be callable, which causes my application to crash because the properties that the stream is trying to write have been released. To solve this problem, I am trying to call cancelPreviousPerformRequestsWithTarget to cancel the previous request, but it does not seem to work. The following are snippets of code.
- (void) viewDidLoad { [self performSelector:@selector(myStopUpdatingLocation) withObject:nil afterDelay:6]; } - (void)viewWillDisappear:(BOOL)animated { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(myStopUpdatingLocation) object:nil]; }
Am I doing something wrong here? The myStopUpdatingLocation method myStopUpdatingLocation defined in the same class that I call the execution requests.
A bit more background. The function I'm trying to implement is to search for users' location, search google for some places around that location, and display a few annotations on the map. In viewDidLoad I start updating the location using the CLLocationManager . I have a timeout after 6 seconds if I don't get the desired accuracy within the timeout, and I use performSelector to do this. What could happen is that the user clicks the back button in the view and this thread will execute, although all my properties have been released, which caused a crash.
Thanks in advance!
James
multithreading iphone request-cancelling
jmurphy
source share