1

Can someone confirm that -checkResourceIsReachableAndReturnError: method of NSURL is working as expected. I have tried using it for known URLs and it is always returning NO. I am using XCode's iPhone Simulator 4.1. Thank you.

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Interfector
  • 1,868
  • 1
  • 23
  • 43

3 Answers3

5

According to NSURL Class Reference

Returns whether the resource pointed to by a file URL can be reached.
...
Discussion
This method is unimplemented in iOS, so it performs no operation

So it only works for file URLs (which your URL probably isn't) and it only works on Mac OS X anyway.

tc.
  • 33,468
  • 5
  • 78
  • 96
4

You can use this method:

- (BOOL) validateUrl: (NSString *) url {
   NSString *theURL =
   @"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
   NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", theURL]; 
   return [urlTest evaluateWithObject:url];
   }
sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161
1

If you just want to know if the URL is valid, you can

NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"yourstring"]];
bool valid = [NSURLConnection canHandleRequest:req];
Adam Shiemke
  • 3,734
  • 2
  • 22
  • 23