in app ios have set database sync icloud. when insert new record data correctly updated , can watch @ container folder. want set switch let user enable or disable core data syncing proccess icloud while app running, dont know how this.
i new ios , icloud. need please. in advance.
this code in appdelegate:
- (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 implementation code handle error appropriately. //abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. //typical reasons error here include: // persistent store not accessible; // schema persistent store incompatible current managed object model. //check error message determine actual problem was. //if persistent store not accessible, there typically wrong file path. often, file url pointing application's resources directory instead of writeable directory. //if encounter schema incompatibility errors during development, can reduce frequency by: // deleting existing store: //[[nsfilemanager defaultmanager] removeitematurl:storeurl error:nil] // performing automatic lightweight migration passing following dictionary options parameter: //@{nsmigratepersistentstoresautomaticallyoption:@yes, nsinfermappingmodelautomaticallyoption:@yes} //lightweight migration work limited set of schema changes; consult "core data model versioning , data migration programming guide" 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; }
do not use ubiquity container. have @ apple documentation excluding file icloud sync. https://developer.apple.com/library/ios/qa/qa1719/_index.html if set bool value no. file again included in files backup. create core data(database) in documents auto sync. using code can disable sync programmatically anytime on click of button. warned app may rejected if database size grows much, because "user data" should syncing icloud.
Comments
Post a Comment