Tuesday, April 30, 2013

NSURL checkResourceIsReachableAndReturnError example ios


checkResourceIsReachableAndReturnError:

Returns whether the resource pointed to by a file URL can be reached.
- (BOOL)checkResourceIsReachableAndReturnError:(NSError **)error
Parameters
error
The error that occurred in the case that the resource cannot be reached.
Return Value of [NSURL checkResourceIsReachableAndReturnError]
YES if the resource is reachable; otherwise, NO.
Example of [NSURL checkResourceIsReachableAndReturnError]
NSURL *theURL = [NSURL fileURLWithPath:@"/Users/elisevanlooij/nonexistingfile.php" 
         isDirectory:NO];
NSError *err;
if ([theURL checkResourceIsReachableAndReturnError:&err] == NO)
    [[NSAlert alertWithError:err] runModal];
Example of [NSURL checkResourceIsReachableAndReturnError]
                // Add all of the suffixes to the URL and test if it exists
                NSString*   nameXX = [name stringByAppendingFormat:@"%@%@.%@", scaleSuffix[ss], deviceSuffix[ds], formatSuffix[fs]];
                NSURL*      testURL = [rootURL URLByAppendingPathComponent:nameXX];
                NSLog(@"testing if image exists: %@", testURL);
                if([testURL checkResourceIsReachableAndReturnError:nil])
                {
                    imageURL = testURL;
                    imageScale = scaleValues[ss];
                    break;
                }