mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-13 11:58:17 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user