coomented by  kstenerud:

if(potentialURL == nil)
{
    return nil;
}

NSString* host = [[NSURL URLWithString:potentialURL] host];
if(host != nil)
{
    return host;
}
return potentialURL;

Otherwise an invalid URL will return nil, causing it to think it's trying reachability to the local network.