Add support for excluding the SQLite store file from iCloud Backups to conform with the iOS Data Storage Guidelines. closes #929

This commit is contained in:
Blake Watters
2012-10-29 01:12:09 -04:00
parent c44f4010fa
commit 6d487dbc9e
3 changed files with 34 additions and 1 deletions

View File

@@ -116,6 +116,7 @@ static RKManagedObjectStore *defaultStore = nil;
if (! self.persistentStoreCoordinator) [self createPersistentStoreCoordinator];
NSURL *storeURL = [NSURL fileURLWithPath:storePath];
if (seedPath) {
BOOL success = [self copySeedDatabaseIfNecessaryFromPath:seedPath toPath:storePath error:error];
if (! success) return nil;
@@ -143,7 +144,23 @@ static RKManagedObjectStore *defaultStore = nil;
if (! [self.persistentStoreCoordinator removePersistentStore:persistentStore error:error]) return nil;
NSDictionary *seedOptions = @{ RKSQLitePersistentStoreSeedDatabasePathOption: (seedPath ?: [NSNull null]) };
return [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nilOrConfigurationName URL:storeURL options:seedOptions error:error];
persistentStore = [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nilOrConfigurationName URL:storeURL options:seedOptions error:error];
if (! persistentStore) return nil;
/**
Exclude the SQLite database from iCloud Backups to conform to the iCloud Data Storage Guidelines
See https://developer.apple.com/icloud/documentation/data-storage/
*/
#if __IPHONE_OS_VERSION_MIN_REQUIRED
BOOL success = [storeURL setResourceValue:@(YES) forKey:NSURLIsExcludedFromBackupKey error:error];
if (!success) {
RKLogError(@"Failed to exclude SQLite store at path '%@' from iCloud Backup: %@", storePath, *error);
return nil;
}
#endif
return persistentStore;
}
- (BOOL)copySeedDatabaseIfNecessaryFromPath:(NSString *)seedPath toPath:(NSString *)storePath error:(NSError **)error