Sqlite与iCloud同步不更新数据

我正在使用iCloud进行多个设备之间的sqlite数据库同步。
我已经在我的应用程序中为sqlite同步实现了这个function。

但是在其他设备上5分钟后数据正在更新。 这是从iCloud方面的问题,因为据我所知我们不能手动更新iCloud。

我知道这是不正确的使用sqlite的icloud同步,但我有更多的100个表,我不能迁移到核心数据。

请在下面find我的代码:

  AppDelegate.m [self checkForiCloudAccess]; [[sqlmessenger shared] fireQueryForCloudData]; 

检查iCloud Access

 -(void)checkForiCloudAccess{ NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; if (ubiq) { NSLog(@"iCloud access at %@", ubiq); isCloudAccees= TRUE; } else { isCloudAccees= FALSE; UIAlertView *alertb = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No iCloud acces" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertb show]; } } 

sqlmessenger.m

消防查询获取iCloud数据

 - (void)fireQueryForCloudData{ NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.xml'", NSMetadataItemFSNameKey]; [query setPredicate:pred]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:query]; [query startQuery]; } - (void)queryDidFinishGathering:(NSNotification *)notification { NSMetadataQuery *que = [[NSMetadataQuery alloc]init]; que = [notification object]; [que disableUpdates]; [que stopQuery]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:que]; self.metaQuery = que; que = nil; UIAlertView *alrView = [[UIAlertView alloc]initWithTitle:@"" message:@"Cloud updated" delegate:Nil cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil]; [alrView show]; //TODO: Comment this stupid method //[self fetcLargeTableFromCloud]; } 

使用元数据查询对象更新数据库

  - (void)loadData:(NSString *)tableName { _TblName = tableName; for (NSMetadataItem *item in [self.metaQuery results]) { NSString *filename = [item valueForAttribute:NSMetadataItemDisplayNameKey]; if([filename isEqualToString:tableName]) { NSURL *url = [item valueForAttribute:NSMetadataItemURLKey]; //Conflict resolve //[fileVersion replaceItemAtURL:url options:0 error:nil]; NSData *file = [NSData dataWithContentsOfURL:url]; [NSFileVersion removeOtherVersionsOfItemAtURL:url error:nil]; NSArray *conflicts = [NSFileVersion unresolvedConflictVersionsOfItemAtURL:url]; for (NSFileVersion *conflict in conflicts) { conflict.resolved = YES; NSLog(@"conflict %@",conflict); } if (file) { _arrCloudData = [[NSMutableArray alloc]init]; _tmpDict = [[NSMutableDictionary alloc]init]; NSXMLParser *parser = [[NSXMLParser alloc] initWithData:file]; [parser setDelegate:self]; [parser parse]; if (_arrCloudData.count !=0) { [self deleteTable:tableName]; _arrColumnList = [self getColumnsForTable:tableName]; //[_arrColumnList removeObjectAtIndex:3]; // [_arrColumnList removeObjectAtIndex:5]; // [_arrColumnList removeObjectAtIndex:8]; NSString *columnNames = [_arrColumnList componentsJoinedByString:@","]; /* NSMutableArray *arrtmp = [NSMutableArray arrayWithArray:_arrColumnList]; for (int i = 0; i<[arrtmp count]; i++) { [arrtmp replaceObjectAtIndex:i withObject:@"?"]; }*/ // NSString *blidString = [arrtmp componentsJoinedByString:@","]; //TODO: Uncomment this lines //NSString *query = [NSString stringWithFormat:@"Insert into %@ (%@) values (%@)",tableName,columnNames,blidString]; //TODO: comment this line NSString *query = [NSString stringWithFormat:@"Insert into %@ (%@) values",tableName,columnNames]; // NSDate *parseFinish = [NSDate date]; //[self insertRowIntblMealDetails:tableName :query]; int exCount = _arrCloudData.count/500; for (int i=0; i<=exCount; i++) { if ([tableName isEqualToString:@"tblRecipeSubtypes"]) { [self insertRowIntblMealDetails:tableName :query:i]; } else{ [self insertRowIntbl:tableName :query :i]; } } /* for (int i=0; i<[_arrCloudData count]; i++) { //Genralized method //[self insertRowInTableName:tableName:i:query]; // //[self insertRowIntblMealDetails:tableName :i :query]; [self insertRowIntblMealDetails:tableName :query]; }*/ sqlite3_close(database); /* NSDate *Complete = [NSDate date]; NSTimeInterval PraseComplete = [parseFinish timeIntervalSinceDate:start]; NSTimeInterval LoopTime = [Complete timeIntervalSinceDate:parseFinish]; NSTimeInterval totalTime = [Complete timeIntervalSinceDate:start]; NSLog(@"Parse Execution Time: %f", PraseComplete); NSLog(@"Loop Execution Time: %f", LoopTime); NSLog(@"Total Execution Time: %@ %f ",tableName, totalTime); */ } else{ NSLog(@"Empty Array %@",tableName); } } else{ NSLog(@"Blank File %@",tableName); } } } } 

我从相应的类调用loaddata来更新数据库。 有无论如何,我可以及早/快速更新数据或在我的代码中有任何问题?

提前致谢