Hey :),
ich steh vor folgendem Problem.
Ich habe schon erfolgreich mein iCloud MagicalRecord Store erstellt und der funktioniert auch super, wenn man diesen von 0 befüllt
Aber da ich jetzt schon viele Daten habe möchte ich diese natürlich auch mit in die iCloud nehmen.
Aber wie genau findet die Migration statt.
Ich habe dazu nur folgenden Thread gefunden der mir aber nicht wirklich weiterhilft.
MagicalRecord Lightweight Migration UND iCloud
Hier schaue ich ob iCloud verfügbar ist. Davor hab ich CoreData immer mit dem else Zweig initialisiert.
Hier ist mein Code für die iCloud Installation
Alles anzeigen
Aber wie kann ich jetzt die alten Daten vom local Store in die iCloud nehmen? Dazu finde ich leider auch nichts im Netz mit Hilfe von Magical Record
Vielen Dank für eure Hilfe.
Lg Dennis
ich steh vor folgendem Problem.
Ich habe schon erfolgreich mein iCloud MagicalRecord Store erstellt und der funktioniert auch super, wenn man diesen von 0 befüllt
Aber da ich jetzt schon viele Daten habe möchte ich diese natürlich auch mit in die iCloud nehmen.
Aber wie genau findet die Migration statt.
Ich habe dazu nur folgenden Thread gefunden der mir aber nicht wirklich weiterhilft.
MagicalRecord Lightweight Migration UND iCloud
Hier ist mein Code für die iCloud Installation
Quellcode
- - (void)iCloudCoreDataSetup {
- // containerID should contain the same string as your iCloud entitlements
- NSString *containerID = [NSString stringWithFormat:@"iCloud.%@", [[NSBundle mainBundle] bundleIdentifier]];
- [MagicalRecord setupCoreDataStackWithiCloudContainer:containerID
- contentNameKey:@"App" // Must not contain dots
- localStoreNamed:@"App.sqlite"
- cloudStorePathComponent:@"Documents/CloudLogs" // Subpath within your ubiquitous container that will contain db change logs
- completion:^{
- // This gets executed after all the setup steps are performed
- // Uncomment the following lines to verify
- NSLog(@"%@", [MagicalRecord currentStack]);
- // NSLog(@"%i events", [Event countOfEntities]);
- }];
- // NOTE: MagicalRecord's setup is asynchronous, so at this point the default persistent store is still probably NIL!
- // Uncomment the following line if you want to check it.
- NSLog(@"%@", [MagicalRecord currentStack]);
- // The persistent store COORDINATOR is however fully setup and can be accessed
- // Uncomment the following line if you want to check it.
- NSLog(@"Store coordinator at this point %@", [NSPersistentStoreCoordinator MR_defaultStoreCoordinator]);
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Finally, store change notifications must be observed. Without these, your app will NOT function properly!
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // This notification is issued only once when
- // 1) you run your app on a particular device for the first time
- // 2) you disable/enable iCloud document storage on a particular device
- // usually a couple of seconds after the respective event.
- // The notification must be handled on the MAIN thread and synchronously
- // (because as soon as it finishes, the persistent store is removed by OS).
- // Refer to Apple's documentation for further details
- [[NSNotificationCenter defaultCenter] addObserverForName:NSPersistentStoreCoordinatorStoresWillChangeNotification
- object:[NSPersistentStoreCoordinator MR_defaultStoreCoordinator]
- // queue:nil // Run on the posting (i.e. background) thread
- queue:[NSOperationQueue mainQueue] // Run on the main thread
- usingBlock:^(NSNotification *note) {
- // For debugging only
- NSLog(@"%s notificationBlockWillChange:%@, isMainThread = %i", __PRETTY_FUNCTION__, note, [NSThread isMainThread]);
- // Disable user interface with setEnabled: or an overlay
- // NOTE: Probably not crucial since the store switch is almost instantaneous.
- // I only hint it here by changing the tint color to red.
- self.window.tintColor = [UIColor redColor];
- // Save changes to current MOC and reset it
- if ([[NSManagedObjectContext MR_defaultContext] hasChanges]) {
- [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
- }
- [[NSManagedObjectContext MR_defaultContext] reset];
- // TODO: Drop any managed object references here
- }];
- // This notification is issued couple of times every time your app starts
- // The notification must be handled on the BACKGROUND thread and asynchronously to prevent deadlock
- // Refer to Apple's documentation for further details
- [[NSNotificationCenter defaultCenter] addObserverForName:NSPersistentStoreCoordinatorStoresDidChangeNotification
- object:[NSPersistentStoreCoordinator MR_defaultStoreCoordinator]
- queue:nil // Run on the posting (i.e. background) thread
- usingBlock:^(NSNotification *note) {
- // For debugging only
- NSLog(@"%s notificationBlockDidChange:%@, isMainThread = %i", __PRETTY_FUNCTION__, note, [NSThread isMainThread]);
- // This block of code must be executed asynchronously on the main thread!
- dispatch_async(dispatch_get_main_queue(), ^{
- // Recommended by Apple
- [[NSManagedObjectContext MR_defaultContext] reset];
- // Notify UI that the data has changes
- // NOTE: I am using the same notification that MagicalRecord sends after merging changes
- [[NSNotificationCenter defaultCenter] postNotificationName:kMagicalRecordPSCDidCompleteiCloudSetupNotification object:nil];
- // Re-enable user interface with setEnabled: or removing the overlay
- // NOTE: Probably not crucial since the store switch is almost instantaneous.
- // I only hint it here by changing the tint color back to default.
- self.window.tintColor = nil;
- });
- }];
- }
Vielen Dank für eure Hilfe.
Lg Dennis