Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two things that I am aware of:</p> <p>1) Files that are generated by your app (and not a result of the user using your app) such as temporary text files to store a variable's value, then these files must be placed in the Library/Cache instead of the Document directory.</p> <p>2) You must also mark a file with a "skip-backup" attribute to tell iCloud not to backup the file.</p> <p>I think you might be missing step 2.</p> <p>I wrote a simple MediaDirectory class which quickly gives me the path to the files in the Library/Cache folder and also add the skip backup attribute. </p> <p>After you saved your file to the Libary/Cache folder, you simply go something like this:</p> <pre><code>[MediaDirectory addSkipBackupAttributeForFile:@"myTextFile.txt"]; </code></pre> <p>Here's the class in full:</p> <pre><code>// Header File // ---------------------------------------------------------------------- // This class takes a file name (including extension) and returns // the path to that file in the Library/Cache folder // ---------------------------------------------------------------------- #import &lt;Foundation/Foundation.h&gt; @interface MediaDirectory : NSObject +(NSString *) mediaPathForFileName:(NSString *) fileName; +(NSString *) mediaPathForFileName:(NSString *) fileName inSubDirectory:(NSString *) subDirectory; + (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName; + (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName inSubDirectory:(NSString *) subDirectory; @end // Implementation File #import "MediaDirectory.h" #include &lt;sys/xattr.h&gt; @implementation MediaDirectory +(NSString *) mediaPathForFileName:(NSString *) fileName { NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachesDirectory = [directoryPaths objectAtIndex:0]; NSString *filePath = [NSString stringWithFormat:@"%@/%@", cachesDirectory, fileName]; return filePath; } // if an image needs to be stored in a sub folder called "images" +(NSString *) mediaPathForFileName:(NSString *) fileName inSubDirectory:(NSString *) subDirectory { NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cachesDirectory = [directoryPaths objectAtIndex:0]; NSString *filePath = [NSString stringWithFormat:@"%@/%@/%@", cachesDirectory, subDirectory, fileName]; return filePath; } //+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL + (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName { const char* filePath = [[self mediaPathForFileName:fileName] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &amp;attrValue, sizeof(attrValue), 0, 0); return result == 0; } + (BOOL)addSkipBackupAttributeToFile:(NSString *) fileName inSubDirectory:(NSString *) subDirectory { const char* filePath = [[self mediaPathForFileName:fileName inSubDirectory:subDirectory] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &amp;attrValue, sizeof(attrValue), 0, 0); return result == 0; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload