2015-07-15 3 views
5

आईओएस के लिए मेरे ऐप में मैंने iCloud के साथ सिंक के लिए अपना डेटाबेस सेट किया है। जब मैं एक नया रिकॉर्ड डालता हूं तो डेटा सही ढंग से अपडेट किया जाता है और मैं इसे अपने कंटेनर फ़ोल्डर में देख सकता हूं। अब मैं ऐप चल रहा है, जबकि iCloud के साथ कोर डेटा सिंकिंग proccess को सक्षम या अक्षम करने के लिए एक स्विच सेट करना चाहता हूं, लेकिन मुझे नहीं पता कि यह कैसे करें।आईओएस आईसीएलएड कोर डेटा स्विच ऐप से बंद

मैं आईओएस और आईसीएलओड के साथ नया हूं। कृपया मदद की ज़रूरत है। अग्रिम में धन्यवाद।

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
    if (_persistentStoreCoordinator != nil) { 
     return _persistentStoreCoordinator; 
    } 

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"myStore.sqlite"];  
    NSURL *cloudRootURL=[fileManager URLForUbiquityContainerIdentifier:nil]; 

    NSString *pathToCloudFile = [[cloudRootURL path]stringByAppendingPathComponent:@"Documents"]; 
    pathToCloudFile = [pathToCloudFile stringByAppendingPathComponent:@"myCloudLogs"]; 

    NSURL *cloudURL = [NSURL fileURLWithPath:pathToCloudFile]; 

    NSString *cloudStoreTitle = @"myStoreCloud"; 
    NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption : @YES, 
          NSInferMappingModelAutomaticallyOption : @YES, 
          NSPersistentStoreUbiquitousContentURLKey: cloudURL, 
          NSPersistentStoreUbiquitousContentNameKey: cloudStoreTitle}; 

    NSError *error = nil; 
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 


    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) { 

     //Replace this implementation with code to handle the error appropriately. 

     //abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

     //Typical reasons for an error here include: 
     // The persistent store is not accessible; 
     // The schema for the persistent store is incompatible with current managed object model. 
     //Check the error message to determine what the actual problem was. 


     //If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory. 

     //If you encounter schema incompatibility errors during development, you can reduce their frequency by: 
     // Simply deleting the existing store: 
     //[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil] 

     // Performing automatic lightweight migration by passing the following dictionary as the options parameter: 
     //@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} 

     //Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details. 


     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 

    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 

    [notificationCenter addObserver:self 
         selector:@selector(processStoresWillChange:) 
          name:NSPersistentStoreCoordinatorStoresWillChangeNotification 
         object:_persistentStoreCoordinator]; 

    [notificationCenter addObserver:self 
         selector:@selector(processStoresDidChange:) 
          name:NSPersistentStoreCoordinatorStoresDidChangeNotification 
         object:_persistentStoreCoordinator]; 

    [notificationCenter addObserver:self 
         selector:@selector(processContentChanges:) 
          name:NSPersistentStoreDidImportUbiquitousContentChangesNotification 
         object:_persistentStoreCoordinator]; 


    return _persistentStoreCoordinator; 
} 
+0

मुझे नहीं लगता कि आप इसे कर सकते हैं। दरअसल मेरी समझ यह है कि मेरे पास एक सतत स्टोयर है जो या तो iCloud सक्षम है या नहीं (यानी आप स्टोर के साथ स्थापित करते समय इसे परिभाषित करते हैं, विकल्प शून्य होते हैं या मान रखते हैं)। इसलिए मैं सुझाव दूंगा कि आपको सभी परिवर्तनों को सहेजना होगा और फिर प्रबंधित ऑब्जेक्ट संदर्भ को रीसेट करना होगा और निरंतर स्टोर को हटा देना होगा और स्टोर ऑप्शन = शून्य (जो तब iCloud सक्षम नहीं है) के साथ एक नया निरंतर स्थापित करें। यदि आप चाहते हैं कि मैं आपको कुछ नमूना कोड दे सकता हूं। – Red

उत्तर

0

सर्वव्यापकता कंटेनर का उपयोग न करें:

यह AppDelegate में मेरी कोड है। Icloud सिंक से फ़ाइल को छोड़कर एप्पल दस्तावेज पर एक नज़र डालें। https://developer.apple.com/library/ios/qa/qa1719/_index.html यदि आप बूल मान को NO पर सेट करते हैं। फ़ाइलों को बैकअप में फ़ाइलों में फिर से शामिल किया जाएगा। ऑटो सिंक के लिए दस्तावेज़ों में कोर डेटा (डेटाबेस) बनाएँ। इस कोड का उपयोग करके आप बटन के क्लिक पर किसी भी समय प्रोग्रामेटिक रूप से सिंक अक्षम कर सकते हैं। लेकिन चेतावनी दी जानी चाहिए कि यदि डेटाबेस का आकार बहुत अधिक बढ़ता है तो ऐप को खारिज कर दिया जा सकता है, क्योंकि केवल "उपयोगकर्ता डेटा" को icloud के साथ समन्वयित किया जाना चाहिए।

संबंधित मुद्दे