User Interaction causes a for loop to move onto the next object
<p>I have an array of objects in which this for loop iterates through. Each object is an IP Address that I test for. However, once the for loop gets to a specific object that fails, the for loop takes roughly 15seconds to a minute to move onto the next object. However, if I interact with the display on my device by tapping, the for loop moves onto the next object. I find this odd because I do call <code>[[UIApplication sharedApplication] beginIgnoringInteractionEvents];</code>. So A) Why is the application still detecting touch events which affect the for loop. And B) I verified that the <code>[[UIApplication sharedApplication] beginIgnoringInteractionEvents];</code> does work because if I try to tap a <code>barButtonItem</code> nothing happens. So here's my question, how can user interaction that's ignored temporarily still cause a for loop to move onto the next object? I've verified that there's no issues with threading/GCD. I know this may be rough to understand without a code sample, however I want to know the principal behind a UI interaction event affecting a for loop. </p>

<p><strong>UPDATE!</strong></p>

<p>Code:</p>

<pre><code>    -(void)beginConnectivitySetupAndTests {
for (int i = 0; i&lt;[extractedDataArray count]; i++) {
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
                    NSString *inStoreObject = [[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectType"];
                    NSString *objectTitle = [[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectTechnicalTitle"];
                    NSString *objectLastOctet = [[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectLastOctet"];
                    NSString *isInfrastructureObject = [[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectIsInfrastructureObject"];
                    NSString *needsAlternateSecondOctet = [[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectablityObjectNeedsAlternateSecondOctet"];
                    NSLog(@"Working with: %@",objectTitle);
                    if ([inStoreObject isEqualToString:@"InStoreObject"]) {

                        if ([needsAlternateSecondOctet isEqualToString:@"YES"]) {
//                            self.deviceIPAddress = nil;
                            NSLog(@"%@", self.deviceIPAddress);
                            NSMutableArray &lt;NSString *&gt; *octets = [self.deviceIPAddress componentsSeparatedByString:@"."];
                            NSString *firstOctetString   = [octets objectAtIndex:0];
                            NSString *secondOctetString  = [octets objectAtIndex:1];
                            NSString *thirdOctetString   = [octets objectAtIndex:2];


                            int secondInt = secondOctetString.intValue;

                            if (secondInt &gt;= 40 &amp;&amp; secondInt &lt;= 47) {
                                [octets removeObjectAtIndex:1];
                                secondOctetString = [NSString stringWithFormat:@"%d", secondInt +40];
                            }

                            else if (secondInt &gt;= 52 &amp;&amp; secondInt &lt;= 53) {
                                [octets removeObjectAtIndex:1];
                                secondOctetString = [NSString stringWithFormat:@"%d", secondInt +100];
                            }

                            else if (secondInt &gt;= 120 &amp;&amp; secondInt &lt;= 121) {
                                [octets removeObjectAtIndex:1];
                                secondOctetString = [NSString stringWithFormat:@"%d", secondInt +100];
                            }

                            else if (secondInt &gt;= 122 &amp;&amp; secondInt &lt;= 123) {
                                [octets removeObjectAtIndex:1];
                                secondOctetString = [NSString stringWithFormat:@"%d", secondInt +40];
                            }

                            else if (secondInt &gt;= 124 &amp;&amp; secondInt &lt;= 125) {
                                [octets removeObjectAtIndex:1];
                                secondOctetString = [NSString stringWithFormat:@"%d", secondInt +40];
                            }

                            else if (secondInt &gt;= 126 &amp;&amp; secondInt &lt;= 127) {
                                [octets removeObjectAtIndex:1];
                                secondOctetString = [NSString stringWithFormat:@"%d", secondInt +40];
                            } else {

                            }
                            NSString *finalString = [NSString stringWithFormat:@"%@.%@.%@.%@", firstOctetString, secondOctetString, thirdOctetString, objectLastOctet];

                            [[extractedDataArray objectAtIndex:i] setValue:[NSString stringWithFormat:@"%@",finalString]forKey:@"ConnectabilityObjectFullIPAddress"];
                            finalIPAddress = finalString;

                            octets = nil;

                        } else {

                            NSMutableArray &lt;NSString*&gt; *octets = [self.deviceIPAddress componentsSeparatedByString:@"."];
                            NSString *firstOctetString = [octets objectAtIndex:0];
                            NSString *secondOctetString = [octets objectAtIndex:1];
                            NSString *thirdOctetString = [octets objectAtIndex:2];
                            [octets removeObjectAtIndex:3];
                            NSString *lastOctet = [NSString stringWithFormat:@"%@", objectLastOctet];

                            NSString *constructedIPAddress = [NSString stringWithFormat:@"%@.%@.%@.%@", firstOctetString, secondOctetString, thirdOctetString, lastOctet];

                            finalIPAddress = constructedIPAddress;
                            [[extractedDataArray objectAtIndex:i] setValue:[NSString stringWithFormat:@"%@",constructedIPAddress]forKey:@"ConnectabilityObjectFullIPAddress"];
                            NSLog(@"%@ IP: %@", objectTitle, constructedIPAddress);
                    }

                    } else {
                        finalIPAddress = [[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectFullIPAddress"];
                    }



                self.ping = [[SimplePing alloc] initWithHostName:finalIPAddress];
                NSLog(@"pinging: %@",finalIPAddress);
                self.ping.delegate = self;

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


                if (pingableObjectAddress) {
                    if (_deviceLatencyString == NULL) {
                        [[extractedDataArray objectAtIndex:i] setValue:[NSString stringWithFormat:@"Successful"] forKey:@"ConnectivityPingTestResultValue"];
                    } else {
                        [[extractedDataArray  objectAtIndex:i] setValue:[NSString stringWithFormat:@"Successful: latency: %@ ms",_deviceLatencyString] forKey:@"ConnectivityPingTestResultValue"];
                    }
                        pingableObjectAddress = nil;
                        CFReadStreamRef readStream;
                        CFWriteStreamRef writeStream;

                        portNumberValue = [[[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectPorts"] intValue];
                        CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)finalIPAddress, portNumberValue, &amp;readStream, &amp;writeStream);

                        inputStream = (NSInputStream*)CFBridgingRelease(readStream);
                        outputStream = (NSOutputStream*)CFBridgingRelease(writeStream);

                        [inputStream setDelegate:self];
                        [outputStream setDelegate:self];

                        [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
                        [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

                        [inputStream open];
                        [outputStream open];

                    NSLog(@"Opening Port for %lu at IP Address %@", (unsigned long)portNumberValue, finalIPAddress);

                        NSString *response  = @"Fly with me!";
                        NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];

                        [outputStream write:[data bytes] maxLength:[data length]];

                    if ([[extractedDataArray objectAtIndex:i] valueForKey:@"ConnectabilityObjectPorts"] != nil ) {

                        if (_connectedPortNumber != 0) {
                            NSLog(@"Port Connection %lu succeeded for %@", (unsigned long)portNumberValue, finalIPAddress);
                            [[extractedDataArray objectAtIndex:i] setValue:@"Successful" forKey:@"ConnectivityPortConnectResultValue"];
                            if (!isInfrastructureObject) {
                                _portConnectionSucceeded = _portConnectionSucceeded + 1;
                                NSLog(@"port connect is not for infrastructure object");
                            }
                            self.connectedPortNumber = 0;
                        } else {
                            if (!isInfrastructureObject) {
                                _portConnectionFailed = _portConnectionFailed + 1;
                            }
                        }
                    }
                    } else {
                        if (!isInfrastructureObject) {
                             pingFailed = pingFailed + 1;
                        }
                    }
            NSLog(@"%lu",(unsigned long)i);
        }
 }

        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];


}
// does have a valid IP address
-(void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address {
    [self.ping sendPingWithData:nil];
}


// device did send packet
-(void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber address:(nonnull NSString *)address {
//    NSLog(@"Sending 64 bytes to %@: icmp_seq=%hu ttl=64", address, sequenceNumber);
    pingTimeoutTimer = [NSTimer scheduledTimerWithTimeInterval:PING_TIMEOUT target:self selector:@selector(timerFired) userInfo:nil repeats:NO];
    _dateRef = [NSDate date];
    NSLog(@"Packet Sent to: %@", address);
}


// timeout timer, fires when a ping back is never recieved
-(void)timerFired {
    NSLog(@"timeout timer fired");
    [pingTimeoutTimer invalidate];
    //self.pingableObjectAddress = nil;
    self.pingTimeoutTimer = nil;
    self.ping = nil;
}

// failed to send packet error handler
-(void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber error:(NSError *)error {
    [self.pingTimeoutTimer invalidate];
    pingTimeoutTimer = nil;

    self.ping = nil;

    if (error) {
        NSLog(@"Ping Error: %@", error);
    }
}

// device did recieve unexpected ping packet, handle this when this happens
-(void)simplePing:(SimplePing *)pinger didReceiveUnexpectedPacket:(NSData *)packet {}

// did recieve response packet
-(void)simplePing:(SimplePing *)pinger didReceivePingResponsePacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber address:(NSString *)address {
    [pingTimeoutTimer invalidate];
    NSDate *end = [NSDate date];
    double latency = [end timeIntervalSinceDate:_dateRef] *1000;
    self.deviceLatencyString = [NSString stringWithFormat:@"%.f", latency];
    self.pingTimeoutTimer = nil;
//    NSLog(@"64 bytes sent to %@: icmp_seq=%hu ttl=64 time = %f ms", address, sequenceNumber, _latency);
    self.pingableObjectAddress = address;
//    NSLog(@"%@", pingableObjectAddress);
    NSLog(@"did recieve packet from: %@", address);
    self.ping = nil;

}


// device failed to ping for failed reason
-(void)simplePing:(SimplePing *)pinger didFailWithError:(NSError *)error {
    NSLog(@"Failed With Error %@", error);
    assert(pinger == self.ping);
    [self.ping stop];

    self.ping = nil;
}
</code></pre>