App Updates, NSURL, and Documents Directory

后端 未结 2 1007
花落未央
花落未央 2020-12-03 12:16

I have an app in the app store that uses Core Data to persist much of the data. The exception is storing images. I store images in subdirectories to the Documents directory

相关标签:
2条回答
  • 2020-12-03 12:45

    I think what you're looking for is the following:

    NSString *appDocumentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    0 讨论(0)
  • 2020-12-03 13:05

    You should use relative URLs to store references to files. The absolute URL is likely to change after an app update

    Files Saved During App Updates

    When a user downloads an app update, iTunes installs the update in a new app directory. It then moves the user’s data files from the old installation over to the new app directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:

    • Application_Home/Documents
    • Application_Home/Library

    Although files in other user directories may also be moved over, you should not rely on them being present after an update.

    https://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTuning/PerformanceTuning.html

    Thx to the sandbox, the application home is also the user home. So it is possible to use the unix tilde which is a short hand to the user home, i.e. ~/Documents, ~/Library and so on.

    Use -[NSString stringByAbbreviatingWithTildeInPath] to turn a full path into a relative ~ path. And reverse it with -[NSString stringByExpandingTildeInPath].

    0 讨论(0)
提交回复
热议问题