Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Copy SQLite Database and excluding it from iCloud
    text
    copied!<p>My application just rejected because I copied sqlite database in NSDocumentDirectory and didn't exclude it from being synced to iCloud. I tried to add code to exclude it from iCloud but it is still occupying same space in iCloud. Here is my code.</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]; [[NSFileManager defaultManager] addSkipBackupAttributeToItemAtURL:toURL]; [[NSFileManager defaultManager] addSkipBackupAttributeToItemAtURL:fromURL]; success = [fileManager copyItemAtURL:fromURL toURL:toURL error:&amp;error]; if (!success) NSLog(@"Failed to create writable database file with message '%@'.", [error localizedDescription]); } } + (NSString *)getDBPath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; return [documentsDir stringByAppendingPathComponent:databaseName]; } </code></pre> <p>Please help.</p>
 

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