0

Im writing a little command line tool that use AFHTTPNetworkng to pull some data from a server and display it. However because AFHTTPNetwotking uses an asynchronous call back, the application exits prior to getting the response from the server. I there for added

NSRunLoop *run = [NSRunLoop currentRunLoop];
_timer = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(check) userInfo:nil repeats:YES];
[run addTimer:_timer forMode:NSDefaultRunLoopMode];
[run runUntilDate:[NSDate distantFuture]];

this timer calls a check method that checks to see if a BOOL has been set to yes (This happens in the call back). If it has it invalidates the timer.

- (void)check{

NSLog(@"checking");

if (test == YES) {
    [_timer invalidate];

}

return;
}

This code works fine but now the app does not terminate, suggesting that the runloop is still running. I could use exit() to kill the app but this does not seem acceptable as this may cause a memory leak.

geminiCoder
  • 2,918
  • 2
  • 29
  • 50
  • possible duplicate of [Can AFNetworking return data synchronously (inside a block)?](http://stackoverflow.com/questions/7969865/can-afnetworking-return-data-synchronously-inside-a-block) – trojanfoe Jan 17 '14 at 16:32
  • The answer in the suggested question is to essentially make the request synchronous. I don't want to do that I just want to stop the program from exiting prior to the call back. I might print out something during the time delay. – geminiCoder Jan 17 '14 at 16:56

0 Answers0