drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 132 forks source link

Leech error #209

Closed pronebird closed 8 years ago

pronebird commented 8 years ago

I use iCloud and an attempt to leech the store leads to this:

Could not leech to ensemble: Error Domain=CDEErrorDomain Code=101 "(null)"

Ubiquitous container ID is nil and as per docs should use default iCloud container.

checkUserIsLoggedIn returns YES which means I am logged in.

My setup looks as following:

// Initialize persistent store
// ...

/* 
 setup ensembles 
 */
NSURL *modelURL = [self URLForMainModel];

CDEICloudFileSystem *cloudFileSystem = [[CDEICloudFileSystem alloc] initWithUbiquityContainerIdentifier:self.containerID];

CDEPersistentStoreEnsemble *ensemble =
[[CDEPersistentStoreEnsemble alloc] initWithEnsembleIdentifier:@"CoreData"
                                            persistentStoreURL:self.storeURL
                                        persistentStoreOptions:self.storeOptions
                                         managedObjectModelURL:modelURL
                                               cloudFileSystem:cloudFileSystem
                                     localDataRootDirectoryURL:nil];

ensemble.delegate = self;

if(!ensemble.isLeeched) {
    [ensemble leechPersistentStoreWithCompletion:^(NSError *error) {
        if (error) NSLog(@"Could not leech to ensemble: %@", error);
    }];
}

Store options are the same i use for my store:

{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
}

Now after some time and after removing the app this issue is gone.. :)

drewmccormack commented 8 years ago

This is probably not related to Ensembles per se. You need to register your app for iCloud in the provisioning portal, and make sure it has the iCloud entitlements setup in Xcode.

You know it is working when you use the ubiquityIdentityToken from NSFIleManager, and it gives a non-nil value. Otherwise it is not setup properly, and you should see Apple’s iCloud setup docs.

If you are trying to use CloudKit, you must use an explicit non-nil container. Eg. iCloud.com http://icloud.com/.mycompany.myapp

Drew

On 29 Dec 2015, at 14:13, Andrey Mikhaylov notifications@github.com wrote:

I use iCloud and an attempt to leech the store leads to this:

Could not leech to ensemble: Error Domain=CDEErrorDomain Code=101 "(null)" Ubiquitous container ID is nil and as per docs should use default iCloud container.

— Reply to this email directly or view it on GitHub https://github.com/drewmccormack/ensembles/issues/209.

pronebird commented 8 years ago

@drewmccormack I have everything setup. I used CoreData with iCloud. I also use iCloud container to upload files to iCloud and KeyValue store. All works. So ubiquityIdentityToken is correct. I'll keep monitoring this issue and if it reappears, I'll try to investigate deeper and let you know.

drewmccormack commented 8 years ago

Does it happen every time, or did it just happen once?

On 29 Dec 2015, at 16:06, Andrey Mikhaylov notifications@github.com wrote:

@drewmccormack https://github.com/drewmccormack I have everything setup. I used CoreData with iCloud. I also use iCloud container to upload files to iCloud and KeyValue store. All works. So ubiquityIdentityToken is right. I'll keep monitoring this issue and if it reappears, I'll try to investigate deeper.

— Reply to this email directly or view it on GitHub https://github.com/drewmccormack/ensembles/issues/209#issuecomment-167806126.

pronebird commented 8 years ago

Was just once in the very beginning of Ensembles adoption. I will know more when I try using Ensembles across my devices. This error happened on Simulator, and from my experience iCloud works quite different on simulator than on actual device.

drewmccormack commented 8 years ago

That error should only arise when something has cancelled the operation.

https://github.com/drewmccormack/ensembles/blob/master/Framework/Source/General/CDEDefines.h#L30

Any idea why that might have happened?

pronebird commented 8 years ago

Wow, I didn't cancel sync for sure. Besides, there is no way to cancel leeching?

It appears to me that I called sync before initial import. It's the only thing I can think of that caused leech or sync to cancel. Don't worry about that for now. I fixed a lot of things in my integration since then so if this happens again I'll reopen the issue and debug the code to see what can be the cause.