objective c - Data duplicate while migrate PersistentStoreCoordinator from local to iCloud -


i doing icloud sync core data works fine. want add on/off switch(migrate store). if migrate store icloud local works fine if migrate icloud datas getting duplicate. tried remove ubiquity container before migrate not helping. not deduplicate because "storedidimportubiquitouscontent" method not called after duplicate data.

code below :

        // migrate local       -(nsurl *)localstoreurl     {         nsurl *storeurl = [[self applicationdocumentsdirectory] urlbyappendingpathcomponent:@"localexpns.sqlite"];         return storeurl;      }    - (void)movestoretolocal {                nserror *error = nil;             nspersistentstorecoordinator * persistentstorecoordinator = self.persistentstorecoordinator;              nspersistentstore * persistentstore = [[persistentstorecoordinator persistentstores] firstobject];              if([[nsfilemanager defaultmanager]fileexistsatpath:[self localstoreurl].path])             {                 nslog(@"file exists");                 [[nsfilemanager defaultmanager] removeitematpath:[self localstoreurl].path error:& error];                 nslog(@"removing error = %@", error);              }              nsmutabledictionary *localstoreoptions = [[self localstoreoptions] mutablecopy];             [localstoreoptions setobject:[nsnumber numberwithbool:yes] forkey:nspersistentstoreremoveubiquitousmetadataoption];             id result = [persistentstorecoordinator migratepersistentstore:persistentstore tourl:[self localstoreurl] options:localstoreoptions withtype:nssqlitestoretype error:&error];  } 

above code working fine.

// migrate icloud back

// fileurl local file url

-(nsurl *)storeurl {     nsurl *storeurl = [[self applicationdocumentsdirectory] urlbyappendingpathcomponent:@"expns.sqlite"];     return storeurl; }       - (void)movestorefiletoicloud:(nsurl*)fileurl      {      nspersistentstorecoordinator * persistentstorecoordinator = self.persistentstorecoordinator;              id sourcestore = [[persistentstorecoordinator persistentstores] firstobject];              if (!sourcestore) {                  nslog(@" failed add old store");              } else {                 nslog(@" added store migrate");                  bool movesuccess = no;                 nserror *error;                   nslog(@" migrate store...");                 // migrate store using icloud options                 id migrationsuccess = [self.persistentstorecoordinator migratepersistentstore:sourcestore tourl:[self storeurl] options:[self icloudstoreoptions] withtype:nssqlitestoretype error:&error];                  if (migrationsuccess) {                     movesuccess = yes;                     nslog(@"store migrated");                      // delete local file                     if (shoulddelete) {                         nslog(@" deleting local store");                         [self deletelocalstore];                     } else {                         nslog(@" not deleting local store");                     }                 }                 else {                     nslog(@"failed migrate store: %@, %@", error, error.userinfo);                 }              }     } 

now data duplicate ever in before migrate. tried remove ubiquity container not helping.

i have solved problem de-duplicate db manually this


Comments