Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You set the skip back attribute to the file before coping it, since the file is not yet copied there the filemanager can't change the properties of that file:</p> <p>Also you are not calling the <code>addSkipBackupAttributeToItemAtURL:</code> on self but on <code>NSFileManager</code> which does have this method declared.</p> <p>You can <code>addSkipBackupAttributeToItemAtURL:</code> from a class method if you declared it as an instance methods, change it to <code>+</code> to make it a class method.</p> <p>Change it to something like:</p> <pre><code>+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { if (&amp;NSURLIsExcludedFromBackupKey == nil) { // iOS &lt;= 5.0.1 const char* filePath = [[URL path] 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; } else { // iOS &gt;= 5.1 NSError *error = nil; [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&amp;error]; return error == nil; } } + (void)copyDatabaseIfNeeded { NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error = nil; NSString *toPath = [self getDBPath]; BOOL success = [fileManager fileExistsAtPath:toPath]; if(!success) { NSString *fromPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; NSURL *toURL = [NSURL fileURLWithPath:toPath]; NSURL *fromURL = [NSURL fileURLWithPath:fromPath]; success = [fileManager copyItemAtURL:fromURL toURL:toURL error:&amp;error]; if (success) { [self addSkipBackupAttributeToItemAtURL:toURL]; } else { NSLog(@"Failed to create writable database file with message '%@'.", [error localizedDescription]); } } } </code></pre> <hr> <p>Also a my comment stated I removed the <code>[[NSFileManager defaultManager] addSkipBackupAttributeToItemAtURL:fromURL];</code> since that file will a not be included in an iCloud backup and b files in the bundle are readonly and can't there for be modified.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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