iOS8 Document directory path

最后都变了- 提交于 2019-12-08 09:29:07

问题


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 retrive document form path

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    • Everythig works good in ios7 simulator & device.
    • But its not locating correct path in ios8 device & also in simulator too.
    • Please anybody help to store & retirve a document in ios8.

回答1:


application Documents directory, it works on every iOS version:

- (NSURL *)applicationDocumentsDirectory {
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}



回答2:


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

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


来源:https://stackoverflow.com/questions/26610439/ios8-document-directory-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!