2
0

Handle store loading errors.

[ADDED]     Detect store loading errors and attempt to recover.
This commit is contained in:
Maarten Billemont 2012-05-09 19:34:00 +02:00
parent 21c0565619
commit c8f9f79bb2
4 changed files with 66 additions and 19 deletions

@ -1 +1 @@
Subproject commit 303b3a3e5c092c21d8e0c92cbe9145b6492b6c7b
Subproject commit b456a34975e65fba8e2228b790706d852188ecb2

View File

@ -13,17 +13,7 @@
static NSDateFormatter *rfc3339DateFormatter = nil;
- (void)loadRFC3339DateFormatter {
if (rfc3339DateFormatter)
return;
rfc3339DateFormatter = [NSDateFormatter new];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
}
#pragma mark - Core Data setup
+ (NSManagedObjectContext *)managedObjectContext {
@ -124,11 +114,6 @@ static NSDateFormatter *rfc3339DateFormatter = nil;
return storeManager;
}
- (NSManagedObjectContext *)managedObjectContextForUbiquityStoreManager:(UbiquityStoreManager *)usm {
return self.managedObjectContext;
}
- (void)saveContext {
[self.managedObjectContext performBlock:^{
@ -184,6 +169,37 @@ static NSDateFormatter *rfc3339DateFormatter = nil;
}];
}
#pragma mark - UbiquityStoreManagerDelegate
- (NSManagedObjectContext *)managedObjectContextForUbiquityStoreManager:(UbiquityStoreManager *)usm {
return self.managedObjectContext;
}
- (void)ubiquityStoreManager:(UbiquityStoreManager *)manager log:(NSString *)message {
dbg(@"StoreManager: %@", message);
}
- (void)ubiquityStoreManager:(UbiquityStoreManager *)manager didEncounterError:(NSError *)error cause:(UbiquityStoreManagerErrorCause)cause context:(id)context {
err(@"StoreManager: cause=%d, context=%@, error=%@", cause, context, error);
}
#pragma mark - Import / Export
- (void)loadRFC3339DateFormatter {
if (rfc3339DateFormatter)
return;
rfc3339DateFormatter = [NSDateFormatter new];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
}
- (MPImportResult)importSites:(NSString *)importedSitesString withPassword:(NSString *)password
askConfirmation:(BOOL(^)(NSUInteger importCount, NSUInteger deleteCount))confirmation {

View File

@ -394,6 +394,37 @@
[controller dismissModalViewControllerAnimated:YES];
}
#pragma mark - UbiquityStoreManagerDelegate
- (void)ubiquityStoreManager:(UbiquityStoreManager *)manager didEncounterError:(NSError *)error cause:(UbiquityStoreManagerErrorCause)cause context:(id)context {
err(@"StoreManager: cause=%d, context=%@, error=%@", cause, context, error);
switch (cause) {
case UbiquityStoreManagerErrorCauseDeleteStore:
case UbiquityStoreManagerErrorCauseCreateStorePath:
case UbiquityStoreManagerErrorCauseClearStore:
break;
case UbiquityStoreManagerErrorCauseOpenLocalStore: {
[PearlAlert showError:@"Could not open your local database.\n\n"
@"The database may be too old. It will be deleted, the application will quit, "
@"and on the next launch a fresh database will be created." tappedButtonBlock:^(UIAlertView *alert, NSInteger buttonIndex) {
wrn(@"Local store could not be opened, deleting it.");
[[NSFileManager defaultManager] removeItemAtURL:context error:nil];
exit(0);
} otherTitles:nil];
break;
}
case UbiquityStoreManagerErrorCauseOpenCloudStore: {
[PearlAlert showError:@"Could not use iCloud-synced storage. Will use a local database for now.\n\n"
@"If this problem persists, you may need to reset your Master Password database on iCloud."];
wrn(@"iCloud store could not be opened, moving to local store.");
[manager useiCloudStore:NO alertUser:NO];
break;
}
}
}
#pragma mark - TestFlight

View File

@ -426,12 +426,12 @@
break;
#ifdef ADHOC
case 7:
[[MPAppDelegate get].storeManager useiCloudStore:![MPAppDelegate get].storeManager.iCloudEnabled];
[[MPAppDelegate get].storeManager useiCloudStore:![MPAppDelegate get].storeManager.iCloudEnabled alertUser:YES];
break;
case 8:
#else
case 6:
[[MPAppDelegate get].storeManager useiCloudStore:![MPAppDelegate get].storeManager.iCloudEnabled];
[[MPAppDelegate get].storeManager useiCloudStore:![MPAppDelegate get].storeManager.iCloudEnabled alertUser:YES];
break;
case 7:
#endif