A block based class to check if a string forms a valid url and if the link is live
- Drag the
URLValidatorfolder into your project. - Drag
URLValidator.handURLValidator.mfiles into your project - Import #URLValidator.h into your class
Provide a string, like so....
NSString *fullURLString = @"http://www.google.com";
URLValidator *myValidator = [[URLValidator alloc]init];
[myValidator validateURLFromString:fullURLString completionHandler:^(URLCheckResult result) {
if (result == URLAccepted){
// The URL is valid
[self.linkButton setEnabled:TRUE];
}
else{
// The URL is invalid
[self.linkButton setEnabled:FALSE];
}
}];
If you get this result then the string couldn't even be made into a url. It might contain spaces or other invalid characters.
If you get this result then the string was made into a URL but no reply was recieved at that address
If you get this result then the string was made into a URL and a reply was recieved from that address. A link with this result should be valid.