Database Reference
In-Depth Information
Once the NSPersistentStore is added to the NSPersistentStoreCoordinator , we check to
make sure it was successful and then notify our UIApplicationDelegate that the
stack initialization is complete and return. It should be noted that it is possible
for the user to turn iCloud back off and be fully robust. We should check to
see whether that situation occurred. If it did, we must migrate back off of
iCloud. That decision branch is left as an exercise for the reader.
iCloud/PPRecipes/PPRAppDelegate.m
storeURL = [docURL URLByAppendingPathComponent:@ "PPRecipes-iCloud.sqlite" ];
NSURL *oldURL = nil;
oldURL = [docURL URLByAppendingPathComponent:@ "PPRecipes.sqlite" ];
if ([fileManager fileExistsAtPath:[oldURL path]]) {
store = [coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:oldURL
options:options
error:&error];
if (!store) {
ALog(@ "Error adding OLD persistent store to coordinator %@\n%@" ,
[error localizedDescription], [error userInfo]);
//Present a user facing error
return ;
}
}
cloudURL = [cloudURL URLByAppendingPathComponent:@ "PPRecipes" ];
[options setValue:[[NSBundle mainBundle] bundleIdentifier]
forKey:NSPersistentStoreUbiquitousContentNameKey];
[options setValue:cloudURL
forKey:NSPersistentStoreUbiquitousContentURLKey];
store = [coordinator migratePersistentStore:store
toURL:storeURL
options:options
withType:NSSQLiteStoreType
error:&error];
if (!store) {
ALog(@ "Error adding OLD persistent store to coordinator %@\n%@" ,
[error localizedDescription], [error userInfo]);
//Present a user facing error
return ;
}
ZAssert([fileManager removeItemAtURL:oldURL error:&error],
@ "Failed to remove old persistent store at %@\n%@\n%@" ,
oldURL, [error localizedDescription], [error userInfo]);
dispatch_sync(dispatch_get_main_queue(), ^{
[self contextInitialized];
});
});
 
 
 
Search WWH ::




Custom Search