1

I need a simple pinger on the iPhone. So I try to get the SimplePing example running on iPhone. But when i init the pinger like in the example, the main runloop does not handle the events generated by SimplePing. Here is the initcode:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

_pinger = [SimplePing simplePingWithHostName:@"192.168.210.1"];
_pinger.delegate = self;
[_pinger start];
NSLog(@"Pinger started");
[self.window makeKeyAndVisible];
return YES; }

If I trigger the runloop directly in this function with somthing like that:

do {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (_pinger != nil);

it works. So my question is, why are the events not processed in the main run loop of UIApplicationMain, and what do I have to do to get this done by the main runloop?

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
user542014
  • 11
  • 3

1 Answers1

0

Well, do something like this:

-(void)stopPinging
{

 NSLog(@"STOP");

 self.pinger = nil;  // or _pinger = nil in your case so that the while loop doesn't   execute again.

 [self.pinger stop]; // this method will call the Simpleping class method stop which takes care of the rest ..


}
Benoit Garret
  • 14,027
  • 4
  • 59
  • 64
user991669
  • 11
  • 1