0

Issue in iOS8 document directory path detection:

  1. Am using following code to store downloaded attachments from my app into documents directory path.

    //-- Store data to documents folder
    NSString *resourceDocPath = [[NSString alloc] initWithString:[ [[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
    NSString *filePath = [resourceDocPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",fileName]];
    [self.downloadedMutableData writeToFile:filePath atomically:YES];
    
  2. Using following code to retrieve document form path

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    • Everything works fine in ios7 simulator & device.
    • But its not locating correct path in ios8 device & also in simulator too.
    • Please anybody help to store & retrieve a document in ios8.
marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Rajesh Loganathan
  • 10,635
  • 4
  • 74
  • 88
  • if you have saved your files somewhere else than the `Document` folder, you are probably in a big trouble on _iOS8_, because the file-structure has been changed and isolated from the application bundle's path... what is your question anyway? – holex Oct 28 '14 at 14:24
  • In iOS 8 document director path location changed. [Check this answer][1] [1]: http://stackoverflow.com/questions/25198840/document-directory-path-of-ios-8-beta-simulator – V.V Oct 30 '14 at 11:03

2 Answers2

1

application Documents directory, it works on every iOS version:

- (NSURL *)applicationDocumentsDirectory {
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
holex
  • 23,420
  • 7
  • 59
  • 73
1

The following code to access document directory works fine in iOS 8.

NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *directory =
    [[fileManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];