Re: Adventures in core-data, iCloud, and sandboxing
Re: Adventures in core-data, iCloud, and sandboxing
- Subject: Re: Adventures in core-data, iCloud, and sandboxing
- From: Roland King <email@hidden>
- Date: Sat, 05 Nov 2011 11:27:12 +0800
That looks about right. I'm still messing about with non SQLite stores but what I'm assuming happens when you set the Ubiquitous* keys in the SQLite store options and migrate, that creates the log files you need for iCloud synching. I really need to go write a test app and mess with this stuff until I grok it properly.
Where in your code are you actually moving the whole thing to iCloud?
Remember also that your SQLite store in the iCloud version is supposed to be somewhere which isn't synched. The recommendation is to put it in a .nosync subdirectory in the ubiquity container (although on iOS I've wondered if just keeping it locally in a non-sync directory in documents would work fine too).
As to your question about broken sync. Can't help you there more than to tell you I've seen a number of other messages about that. Some people for testing are changing the directory name (from test1 to test2 etc) and there are also suggestions that you run something to clean out the ubiquitous store, like this
BOOL cleanUbiquitousFolder = YES;
if (cleanUbiquitousFolder)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtURL:[fileManager URLForUbiquityContainerIdentifier:nil] error:nil];
return NO;
}
I'm pleased you got this going so quickly, I struggled to get my simple document based app to work with a dumb binary store in the cloud and figured SQLite would add another layer of pain.
On Nov 5, 2011, at 12:24 AM, Martin Hewitson wrote:
>
> On 4, Nov, 2011, at 03:06 PM, Roland King wrote:
>
>>
>> On Nov 4, 2011, at 1:41 PM, Martin Hewitson wrote:
>>
>>>
>>> On 4, Nov, 2011, at 02:01 AM, Roland King wrote:
>>>
>>>>
>>>>
>>>>
>>>>
>>>>> So, can I conclude from this that iCloud and core-data only works with SQL store? The WWDC video hints at this, but was not explicit.
>>>>>
>>>>
>>>> Not so. I have a core data app running using icloud and an XML store. This is ios by the way and the store is not incremental, it's just being treated as a blob which is fully synced each time but it's small so that's ok.
>>>>
>>>> Definitely if you want the incremental log style store you have to use SQL but in general core data in iCloud will let you use whatever you like.
>>>
>>> I hadn't realised that I had made a choice. How does one choose an incremental store as opposed to a blob? Any pointers how you got your core-data iCloud app working would be greatly appreciated!
>>
>> Those two keys you add when you open the persistent store, NSPersistentStoreUbiquitousContentNameKey and NSPersistentStoreUbiquitousContentURLKey are the ones which tell Core Data you're using the log file based core data (only available with SQLite). So with that store, the actual SQLite database isn't in the cloud, it's kept local, but a log file directory is created which is in the cloud and deltas are synched up there. The idea is that each client just brings down the log files and updates the database at a record level. Those keys only mean anything with the SQLite store, which may be why you're having issues with migration. I don't use any of those keys, I just have my store as a local file which is synched wholesale.
>>
>> For your original mail, you want to migrate to SQLLite and then also migrate to iCloud. I don't know if you can do that easily in one step. If I were looking at this I would probably think of creating a new SQLLite store for the migration, empty, opening the old local XML store and then migrating the objects over with code. Whether you choose to make the new SQLite store local and then migrate it up to iCloud or make it in the cloud and then update it is a question I don't have a good answer to, I'm still a little confused by how the initial log files get magically created when you migrate a document to iCloud, I'm definitely missing a piece of information somewhere.
>
> I think I've achieved this migration step with code like this:
>
> NSURL *oldURL = [NSURL fileURLWithPath:[applicationSupportDirectory stringByAppendingPathComponent:oldStoreName]];
> NSURL *newURL = [NSURL fileURLWithPath:[applicationSupportDirectory stringByAppendingPathComponent:storeName]];
>
> persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
> if ([fileManager fileExistsAtPath:[oldURL path]]) {
> NSError *error = nil;
> NSPersistentStore *store = [persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
> configuration:nil
> URL:oldURL
> options:options
> error:&error];
> if (!store){
> [[NSApplication sharedApplication] presentError:error];
> [persistentStoreCoordinator release], persistentStoreCoordinator = nil;
> return nil;
> }
>
>
> // now add iCloud options
> [options setObject:storeName forKey:NSPersistentStoreUbiquitousContentNameKey];
> NSURL *contentURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:containerID];
> [options setObject:contentURL forKey:NSPersistentStoreUbiquitousContentURLKey];
> [options setObject:[NSNumber numberWithBool:YES] forKey:NSValidateXMLStoreOption];
>
> // migrate it
> store = [persistentStoreCoordinator migratePersistentStore:store toURL:newURL options:options withType:NSSQLiteStoreType error:&error];
> if (error) {
> [NSApp presentError:error];
> return nil;
> }
>
> // archive old store
> [fileManager moveItemAtURL:oldURL toURL:[oldURL URLByAppendingPathExtension:@"xml"] error:&error];
> if (error) {
> [NSApp presentError:error];
> }
>
> } else {
> // add iCloud
> [options setObject:storeName forKey:NSPersistentStoreUbiquitousContentNameKey];
> NSURL *contentURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:containerID];
> [options setObject:contentURL forKey:NSPersistentStoreUbiquitousContentURLKey];
>
> // make a new persistent store coordinator
> if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
> configuration:nil
> URL:newURL
> options:options
> error:&error]){
> [[NSApplication sharedApplication] presentError:error];
> [persistentStoreCoordinator release], persistentStoreCoordinator = nil;
> return nil;
> }
> }
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Martin Hewitson
> Albert-Einstein-Institut
> Max-Planck-Institut fuer
> Gravitationsphysik und Universitaet Hannover
> Callinstr. 38, 30167 Hannover, Germany
> Tel: +49-511-762-17121, Fax: +49-511-762-5861
> E-Mail: email@hidden
> WWW: http://www.aei.mpg.de/~hewitson
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Adventures in core-data, iCloud, and sandboxing (From: Martin Hewitson <email@hidden>) |
| >Re: Adventures in core-data, iCloud, and sandboxing (From: Roland King <email@hidden>) |
| >Re: Adventures in core-data, iCloud, and sandboxing (From: Martin Hewitson <email@hidden>) |
| >Re: Adventures in core-data, iCloud, and sandboxing (From: Roland King <email@hidden>) |
| >Re: Adventures in core-data, iCloud, and sandboxing (From: Martin Hewitson <email@hidden>) |