2
0

iOS 7 cloud loading.

This commit is contained in:
Maarten Billemont 2013-09-08 10:42:28 -04:00
parent 8ea0f00cf0
commit 36386c3213
6 changed files with 91 additions and 90 deletions

@ -1 +1 @@
Subproject commit 5a19df087f7a694ad6427708f6d23c62ad8999bb Subproject commit a2ce82ea58d8a02237f33fdc4393259b09cb4967

View File

@ -263,8 +263,9 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
withIntermediateDirectories:YES attributes:nil error:&error]) withIntermediateDirectories:YES attributes:nil error:&error])
err(@"While creating directory for new local store: %@", error); err(@"While creating directory for new local store: %@", error);
if (![self.storeManager copyMigrateStore:oldLocalStoreURL withOptions:oldLocalStoreOptions if (![self.storeManager migrateStore:oldLocalStoreURL withOptions:oldLocalStoreOptions
toStore:newLocalStoreURL withOptions:newLocalStoreOptions toStore:newLocalStoreURL withOptions:newLocalStoreOptions
strategy:self.storeManager.migrationStrategy
error:nil cause:nil context:nil]) { error:nil cause:nil context:nil]) {
self.storeManager.localStoreURL = oldLocalStoreURL; self.storeManager.localStoreURL = oldLocalStoreURL;
return NO; return NO;
@ -310,12 +311,10 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
if (![[NSFileManager defaultManager] createDirectoryAtPath:[self.storeManager URLForCloudStoreDirectory].path if (![[NSFileManager defaultManager] createDirectoryAtPath:[self.storeManager URLForCloudStoreDirectory].path
withIntermediateDirectories:YES attributes:nil error:&error]) withIntermediateDirectories:YES attributes:nil error:&error])
err(@"While creating directory for new cloud store: %@", error); err(@"While creating directory for new cloud store: %@", error);
if (![[NSFileManager defaultManager] createDirectoryAtPath:[self.storeManager URLForCloudContent].path
withIntermediateDirectories:YES attributes:nil error:&error])
err(@"While creating directory for new cloud content: %@", error);
if (![self.storeManager copyMigrateStore:oldCloudStoreURL withOptions:oldCloudStoreOptions if (![self.storeManager migrateStore:oldCloudStoreURL withOptions:oldCloudStoreOptions
toStore:newCloudStoreURL withOptions:newCloudStoreOptions toStore:newCloudStoreURL withOptions:newCloudStoreOptions
strategy:self.storeManager.migrationStrategy
error:nil cause:nil context:nil]) error:nil cause:nil context:nil])
return NO; return NO;

View File

@ -74,83 +74,83 @@
- (void)switchCloudStore { - (void)switchCloudStore {
NSError *error = nil; // NSError *error = nil;
NSURL *cloudStoreDirectory = [[MPiOSAppDelegate get].storeManager URLForCloudStoreDirectory]; // NSURL *cloudStoreDirectory = [[MPiOSAppDelegate get].storeManager URLForCloudStoreDirectory];
NSURL *cloudContentDirectory = [[MPiOSAppDelegate get].storeManager URLForCloudContentDirectory]; // NSURL *cloudContentDirectory = [[MPiOSAppDelegate get].storeManager URLForCloudContentDirectory];
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:cloudContentDirectory includingPropertiesForKeys:nil // NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:cloudContentDirectory includingPropertiesForKeys:nil
options:NSDirectoryEnumerationSkipsHiddenFiles error:&error]; // options:NSDirectoryEnumerationSkipsHiddenFiles error:&error];
if (!contents) // if (!contents)
err(@"While enumerating cloud contents: %@", error); // err(@"While enumerating cloud contents: %@", error);
//
BOOL directory; // BOOL directory;
NSMutableDictionary *stores = [NSMutableDictionary dictionaryWithCapacity:[contents count]]; // NSMutableDictionary *stores = [NSMutableDictionary dictionaryWithCapacity:[contents count]];
NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil]; // NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil];
NSPersistentStoreCoordinator *storePSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; // NSPersistentStoreCoordinator *storePSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSFetchRequest *usersFetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPUserEntity class] )]; // NSFetchRequest *usersFetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPUserEntity class] )];
NSFetchRequest *sitesFetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPElementEntity class] )]; // NSFetchRequest *sitesFetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPElementEntity class] )];
for (NSURL *content in contents) // for (NSURL *content in contents)
if ([[NSFileManager defaultManager] fileExistsAtPath:content.path isDirectory:&directory] && directory) { // if ([[NSFileManager defaultManager] fileExistsAtPath:content.path isDirectory:&directory] && directory) {
NSString *contentString = [content lastPathComponent]; // NSString *contentString = [content lastPathComponent];
NSUInteger firstDash = [contentString rangeOfString:@"-" options:0].location; // NSUInteger firstDash = [contentString rangeOfString:@"-" options:0].location;
NSString *storeDescription = firstDash == NSNotFound? contentString: [contentString substringToIndex:firstDash]; // NSString *storeDescription = firstDash == NSNotFound? contentString: [contentString substringToIndex:firstDash];
NSPersistentStore *store = nil; // NSPersistentStore *store = nil;
@try { // @try {
NSURL *storeURL = [[cloudStoreDirectory // NSURL *storeURL = [[cloudStoreDirectory
URLByAppendingPathComponent:[content lastPathComponent] isDirectory:NO] // URLByAppendingPathComponent:[content lastPathComponent] isDirectory:NO]
URLByAppendingPathExtension:@"sqlite"]; // URLByAppendingPathExtension:@"sqlite"];
if (!(store = [storePSC addPersistentStoreWithType:NSSQLiteStoreType configuration:nil // if (!(store = [storePSC addPersistentStoreWithType:NSSQLiteStoreType configuration:nil
URL:storeURL options:@{ // URL:storeURL options:@{
NSPersistentStoreUbiquitousContentNameKey : [[MPiOSAppDelegate get].storeManager valueForKey:@"contentName"], // NSPersistentStoreUbiquitousContentNameKey : [[MPiOSAppDelegate get].storeManager valueForKey:@"contentName"],
NSPersistentStoreUbiquitousContentURLKey : content, // NSPersistentStoreUbiquitousContentURLKey : content,
NSMigratePersistentStoresAutomaticallyOption : @YES, // NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES, // NSInferMappingModelAutomaticallyOption : @YES,
NSPersistentStoreFileProtectionKey : NSFileProtectionComplete // NSPersistentStoreFileProtectionKey : NSFileProtectionComplete
} error:&error])) { // } error:&error])) {
wrn(@"Couldn't describe store opening %@: %@", [content lastPathComponent], error); // wrn(@"Couldn't describe store opening %@: %@", [content lastPathComponent], error);
continue; // continue;
} // }
//
NSUInteger userCount, siteCount; // NSUInteger userCount, siteCount;
NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; // NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
moc.persistentStoreCoordinator = storePSC; // moc.persistentStoreCoordinator = storePSC;
if ((userCount = [moc countForFetchRequest:usersFetchRequest error:&error]) == NSNotFound) { // if ((userCount = [moc countForFetchRequest:usersFetchRequest error:&error]) == NSNotFound) {
wrn(@"Couldn't describe store userCount %@: %@", [content lastPathComponent], error); // wrn(@"Couldn't describe store userCount %@: %@", [content lastPathComponent], error);
continue; // continue;
} // }
if ((siteCount = [moc countForFetchRequest:sitesFetchRequest error:&error]) == NSNotFound) { // if ((siteCount = [moc countForFetchRequest:sitesFetchRequest error:&error]) == NSNotFound) {
wrn(@"Couldn't describe store siteCount %@: %@", [content lastPathComponent], error); // wrn(@"Couldn't describe store siteCount %@: %@", [content lastPathComponent], error);
continue; // continue;
} // }
//
storeDescription = PearlString( @"%@: %dU, %dS", storeDescription, userCount, siteCount ); // storeDescription = PearlString( @"%@: %dU, %dS", storeDescription, userCount, siteCount );
} // }
@catch (NSException *exception) { // @catch (NSException *exception) {
wrn(@"Couldn't describe store %@: exception %@", [content lastPathComponent], exception); // wrn(@"Couldn't describe store %@: exception %@", [content lastPathComponent], exception);
} // }
@finally { // @finally {
if (store) if (![storePSC removePersistentStore:store error:&error]) // if (store) if (![storePSC removePersistentStore:store error:&error])
wrn(@"Couldn't remove store %@: %@", [content lastPathComponent], error); // wrn(@"Couldn't remove store %@: %@", [content lastPathComponent], error);
[stores setObject:storeDescription forKey:[content lastPathComponent]]; // [stores setObject:storeDescription forKey:[content lastPathComponent]];
} // }
} // }
//
NSString *storeUUID = [[MPiOSAppDelegate get].storeManager valueForKey:@"storeUUID_ThreadSafe"]; // NSString *storeUUID = [[MPiOSAppDelegate get].storeManager valueForKey:@"storeUUID_ThreadSafe"];
NSUInteger firstDash = [storeUUID rangeOfString:@"-" options:0].location; // NSUInteger firstDash = [storeUUID rangeOfString:@"-" options:0].location;
PearlArrayTVC *vc = [[PearlArrayTVC alloc] initWithStyle:UITableViewStylePlain]; // PearlArrayTVC *vc = [[PearlArrayTVC alloc] initWithStyle:UITableViewStylePlain];
vc.title = PearlString( @"Current: %@", firstDash == NSNotFound? storeUUID: [storeUUID substringToIndex:firstDash] ); // vc.title = PearlString( @"Current: %@", firstDash == NSNotFound? storeUUID: [storeUUID substringToIndex:firstDash] );
[stores enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { // [stores enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[vc addRowWithName:obj style:PearlArrayTVCRowStyleLink toggled:NO toSection:@"Cloud Stores" // [vc addRowWithName:obj style:PearlArrayTVCRowStyleLink toggled:NO toSection:@"Cloud Stores"
activationBlock:^BOOL(BOOL wasToggled) { // activationBlock:^BOOL(BOOL wasToggled) {
[[MPiOSAppDelegate get].storeManager setValue:key forKey:@"storeUUID"]; // [[MPiOSAppDelegate get].storeManager setValue:key forKey:@"storeUUID"];
[[MPiOSAppDelegate get].storeManager reloadStore]; // [[MPiOSAppDelegate get].storeManager reloadStore];
[[MPiOSAppDelegate get] signOutAnimated:YES]; // [[MPiOSAppDelegate get] signOutAnimated:YES];
return YES; // return YES;
}]; // }];
}]; // }];
dispatch_async( dispatch_get_main_queue(), ^{ // dispatch_async( dispatch_get_main_queue(), ^{
[switchCloudStoreProgress cancelAlertAnimated:YES]; // [switchCloudStoreProgress cancelAlertAnimated:YES];
[self.navigationController pushViewController:vc animated:YES]; // [self.navigationController pushViewController:vc animated:YES];
} ); // } );
} }
- (IBAction)toggleLevelControl:(UISegmentedControl *)sender { - (IBAction)toggleLevelControl:(UISegmentedControl *)sender {

View File

@ -31,7 +31,7 @@
[super viewDidAppear:animated]; [super viewDidAppear:animated];
if (self.cloudSwitch && [[MPiOSConfig get].iCloudDecided boolValue]) if (self.cloudSwitch && [[MPiOSConfig get].iCloudDecided boolValue])
self.cloudSwitch.on = [MPiOSAppDelegate get].storeManager.cloudEnabled; self.cloudSwitch.on = [[MPiOSConfig get].iCloudEnabled boolValue];
if (self.rememberLoginSwitch) if (self.rememberLoginSwitch)
self.rememberLoginSwitch.on = [[MPiOSConfig get].rememberLogin boolValue]; self.rememberLoginSwitch.on = [[MPiOSConfig get].rememberLogin boolValue];
} }

View File

@ -593,7 +593,9 @@
- (void)checkConfig { - (void)checkConfig {
// iCloud enabled / disabled // iCloud enabled / disabled
if ([[MPiOSConfig get].iCloudEnabled boolValue] != self.storeManager.cloudEnabled) { BOOL iCloudEnabled = [[MPiOSConfig get].iCloudEnabled boolValue];
BOOL cloudEnabled = self.storeManager.cloudEnabled;
if (iCloudEnabled != cloudEnabled) {
if ([[MPiOSConfig get].iCloudEnabled boolValue]) if ([[MPiOSConfig get].iCloudEnabled boolValue])
[self.storeManager setCloudEnabledAndOverwriteCloudWithLocalIfConfirmed:^(void (^setConfirmationAnswer)(BOOL answer)) { [self.storeManager setCloudEnabledAndOverwriteCloudWithLocalIfConfirmed:^(void (^setConfirmationAnswer)(BOOL answer)) {
[PearlAlert showAlertWithTitle:@"Keep Sites?" [PearlAlert showAlertWithTitle:@"Keep Sites?"

View File

@ -24,7 +24,7 @@
NSStringFromSelector( @selector(typeTipShown) ) : @(!self.firstRun), NSStringFromSelector( @selector(typeTipShown) ) : @(!self.firstRun),
NSStringFromSelector( @selector(loginNameTipShown) ) : @NO, NSStringFromSelector( @selector(loginNameTipShown) ) : @NO,
NSStringFromSelector( @selector(traceMode) ) : @NO, NSStringFromSelector( @selector(traceMode) ) : @NO,
NSStringFromSelector( @selector(iCloudEnabled) ) : @YES NSStringFromSelector( @selector(iCloudEnabled) ) : @NO
}]; }];
return self; return self;