Search code examples
iosobjective-ciphonexcode5

How to read download file from path in ios


I have tried to download and read a file (pdf/epub). I have achieved download and save the file in below path.

Download path is - file path

/Users/apple/Library/Application Support/iPhone Simulator/7.1/Applications/B5C69537-DBAA-45DA-BDF3-84D0F038378D/Documents/3471.epub

But I unable to read from the same path. I am using the below coding for reading the file path.

NSString *testpath =[[NSBundle mainBundle] pathForResource:@"3471" ofType:@"epub"];

Solution

  • NSBundle mainBundle is for the files added to the project folder.

    If you need to find any downloaded files saved to documents folder means, try

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *testpath = [documentsDirectory stringByAppendingPathComponent:filename];