iCloud + Storage of media in iPhone Documents folder

前端 未结 2 1675
滥情空心
滥情空心 2020-12-15 09:26

I, like many developers, got an email from Apple recently that stated we should move our data from the documents directory into another folder to permit more streamlined bac

相关标签:
2条回答
  • 2020-12-15 09:52

    Library/Caches is probably a good answer for many apps. Especially when the app will work fine is cached data is lost and clearing the cache does not also destroy all record of what data a user might have elected to cache and where it can be re-obtained from.

    For apps which have data which does not belong in Caches consider Library/Application Support.

    http://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1

    Application Support:

    Use this directory to store all application data files except those associated with the user’s documents. For example, you might use this directory to store application-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the application. An application might use this directory to store a modifiable copy of resources contained initially in the application’s bundle. A game might use this directory to store new levels purchased by the user and downloaded from a server.

    All content in this directory should be placed in a custom subdirectory whose name is that of your application’s bundle identifier or your company.

    In iOS, the contents of this directory are backed up by iTunes.


    Unfortunately the Application Support directory is still backed up and falls under Apple's new data storage guidelines. Depending on how sensitive reviewers choose to be about total backed up file size this may still lead to rejections.

    0 讨论(0)
  • 2020-12-15 10:12

    iOS 5.0.1 introduced a flag to address this issue:

    https://developer.apple.com/library/ios/#qa/qa1719/_index.html

    Their recommendation is to create a folder in /Library/ like /Library/PrivateDocs , and put your files there. However you will also have to set a "do not backup" flag on them as every file in /Library except for those in /Library/Cache or tmp are backed up by default. Set the flag on PrivateDocs folder with this command:

    #include <sys/xattr.h>
    - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
    {
        const char* filePath = [[URL path] fileSystemRepresentation];
    
        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;
    
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    }
    
    0 讨论(0)
提交回复
热议问题