I am working with coredata for the first time, and I need to limit the sqlite db file from the iCloud backup located in the documents directory, and I did this using the code below
-(id)init { if((self = [super init])) { NSURL* documentsDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; NSURL* modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"]; NSURL* giveForwardSqliteURL = [documentsDirectoryURL URLByAppendingPathComponent:@"InfoCollection.sqlite"]; NSError* error; m_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; m_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:m_managedObjectModel]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; if ([m_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:giveForwardSqliteURL options:options error:&error]) { m_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [m_managedObjectContext setPersistentStoreCoordinator:m_persistentStoreCoordinator]; [self addSkipBackupAttributeToItemAtPath:giveForwardSqliteURL]; } else { NSLog(@"Failed to create or open database: %@", [error userInfo]); return nil; } } return self; }
// Prevent iCloud from backing up the document catalog folder
- (BOOL)addSkipBackupAttributeToItemAtPath:(NSURL *) URL { assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); NSError *error = nil; BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: &error]; if(!success){ NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); } return success; }
Now that I did not understand, we also need to limit the sqlite-wal and sqlite-shm files from the icloud backup, if so, how to limit the sqlite-wal and sqlite-shm files from the icloud backup
And I want a solution without changing the location of db sqlite from the document directory folder ... how can we do this
Please correct if something is wrong in the above code.
Thanks in advance
ios sqlite core-data icloud
kumar
source share