lmirosevic / GBPing

Highly accurate ICMP Ping controller for iOS
Apache License 2.0
279 stars 87 forks source link

Get result from delegate #28

Closed Oscar053 closed 7 years ago

Oscar053 commented 8 years ago

Hi, I've implemented your classes in my xCode project. Everything works fine but I have a specific problem with synchronicity.

I provide a method that pings N hosts in my LAN. I need to know if every Ping goes well or not, but I can know this only through delegate methods.

Code was inserted into PingHelper.m class.

` for(int i=1; i< pow(2,(32-netmask)) -1; i++){

    ph[i] = [[PingHelper alloc] init];

    NSString *finalAddr = [IPHelper composeIPv4:addrs[0] netmask:netmask host:i];

    [ph[i] ping:finalAddr semaphore:NULL];

    data.generic_counter++;

}`

And PingHelper contains:

`-(BOOL)ping:(NSString*)host semaphore:(dispatch_semaphore_t)sem{ self->ping = [[GBPing alloc] init]; self->ping.host = host; self->ping.delegate = self; self->ping.timeout = 1.0; self->ping.pingPeriod = 0.9;

[self->ping setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
    if (success) {
        //start pinging
        [self->ping startPinging];

    }
    else {
        NSLog(@"failed to start");
    }
}];

//while(!finished);
return result;

}`

Any help will be appreciated. Thanks, Emanuele