-1

Below is what I have

NSString *foofile = @"/Users/alkandari/Library/Application Support/iPhone Simulator/6.1/Applications/8C445026-6387-4E40-B5A3-D1A1680666D6/Documents/ProjacsBODFiles/file_5_21.pdf"
NSURL *url;
if (fileExists) {
    url = [NSURL URLWithString:foofile];
    NSLog(@"taking local file 1 ... %@==%@", url, foofile);
} else {

    url=[NSURL URLWithString:address];
    NSLog(@"taking internet file 1... %@", url);
}

When I execute, I get log as below

taking local file 1 ... (null)==/Users/alkandari/Library/Application Support/iPhone Simulator/6.1/Applications/8C445026-6387-4E40-B5A3-D1A1680666D6/Documents/ProjacsBODFiles/file_5_21.pdf

I don't understand why I am getting URL as null. Because of that I am not able to open file.

Any idea why I am getting URL as null above?

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

2 Answers2

1

You will need to use fileURLWithPath for path to the localfile system:

NSString *foofile = @"/Users/alkandari/Library/Application Support/iPhone Simulator/6.1/Applications/8C445026-6387-4E40-B5A3-D1A1680666D6/Documents/ProjacsBODFiles/file_5_21.pdf"
NSURL *url;
if (fileExists) {
    url = [NSURL fileURLWithPath:foofile];
    NSLog(@"taking local file 1 ... %@==%@", url, foofile);
} else {
...
}
rckoenes
  • 69,092
  • 8
  • 134
  • 166
1

You can also reach the file in your simulator folder by using the following code;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *libraryBaseDirectory = [paths objectAtIndex:0];

NSString *privateDocumentsDirectory = [libraryBaseDirectory stringByAppendingPathComponent:@"ProjacsBODFiles"];
Engnyl
  • 1,380
  • 16
  • 24