0

医療記録を保存するアプリを開発しています。単一のコンテキストと単一の物理ストアでコア データを使用しています。[managedObjectContext save:&error] を呼び出したにもかかわらず、Xcode 経由でコンテナーを抽出すると、sqlite db に最新のデータが表示されません。

ここで提案されているようなことを試してみました: Core data not Saving my dataですが、うまくいきませんでした。さらに悪いことに、しばらくするとデータが表示されます。アプリは FTP 経由で sqlite を送信して、災害復旧用のデータをダンプできます。先週分の作業が常に表示されるとは限りませんが、通常は 1 週間後の作業が表示されます。

私が理解できないのは、[managedObjectContext save:&error] は物理ストアにデータをすぐに書き込むのですか? (私の推測では NO です) その場でデータを書き留めてほしいとコア データに伝えるにはどうすればよいですか (それが実際に可能である場合)。アプリを閉じるか、デバイスを再起動すると、コア データが sqlite に書き込まれますか?

編集 1 - いくつかのコードを追加する [managedObjectContext save:&error] は、[CommonHelper SaveData:true]; 内で呼び出されます。@try ブロックの先頭に。

_FollowUp.bMI=[NSNumber numberWithFloat: [TextBMI.text floatValue]];
    _FollowUp.karfnosky=[NSNumber numberWithInt: [TextKarfnosky.text intValue]];
    _FollowUp.charlson=[NSNumber numberWithInt: [TextCharlson.text intValue]];
    _FollowUp.alimentazione=ButtonAlimentazione.titleLabel.text;
    _FollowUp.farmaci=TextFarmaci.text;
    _FollowUp.dolore=ButtonDolore.titleLabel.text;


    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];


    @try {
        [CommonHelper SaveData:true];            


        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@“Data saved” message: @“Record saved successfully” delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];


        float height = self.view.bounds.size.height;
        float width = self.view.bounds.size.width;
        lblSincro = [[UILabel alloc]initWithFrame:CGRectMake(width/2-200 ,height/2+30, 400, 20)];
        lblSincro.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        lblSincro.font = [UIFont boldSystemFontOfSize:16.0f];
        lblSincro.numberOfLines = 1;
        [lblSincro setTextAlignment:NSTextAlignmentCenter];
        lblSincro.backgroundColor = [UIColor clearColor];
        lblSincro.textColor = [UIColor whiteColor];
        lblSincro.text = @"Uploading in progress";

        UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] ;
        spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] ;
        spinner.frame = CGRectMake(0, 0,  width,height);
        spinner.tag = 3;
        UIColor *color = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
        spinner.backgroundColor =color;

        lblSincroDet = [[UILabel alloc]initWithFrame:CGRectMake(width/2-200 ,height/2+70, 400, 20)];
        lblSincroDet.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        lblSincroDet.font = [UIFont boldSystemFontOfSize:16.0f];
        lblSincroDet.numberOfLines = 1;
        [lblSincroDet setTextAlignment:NSTextAlignmentCenter];
        lblSincroDet.backgroundColor = [UIColor clearColor];
        lblSincroDet.textColor = [UIColor whiteColor];

        [self.view addSubview:lblSincro];
        [self.view addSubview:lblSincroDet];
        [self.view addSubview:spinner];

        [spinner addSubview:lblSincro];
        [spinner addSubview:lblSincroDet];

        [spinner startAnimating];

        dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){

            SyncHelper *sync=[SyncHelper alloc];
            BOOL result=sync.Sincronize;

            dispatch_async(dispatch_get_main_queue(), ^(void){
                [spinner stopAnimating];
                [lblSincro removeFromSuperview];
                [lblSincroDet removeFromSuperview];

                [lblSincro removeFromSuperview];
                if(result){
                    _SaveView  = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"successSincro", @"") message:NSLocalizedString(@"successSincroMessage", @"") delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                    [_SaveView show];
                }else{
                    _SaveView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"failedSincro", @"") message:NSLocalizedString(@"failedSincroMessage", @"")
                                                          delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                    [_SaveView show];
                }
            });
        });
        _FollowUpLoad=_FollowUp;
        _isNew=false;
    }@catch (NSException *ex)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message: @“Failed to save data” delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
4

2 に答える 2

0

CoreData はデフォルトでWrite-Ahead Loggingを使用するため、これを無効にしない限り、.sqlite ファイルにすべてのデータが含まれるとは限りません。

そのようです...

NSDictionary *options = @{
     NSMigratePersistentStoresAutomaticallyOption : @YES,
     NSInferMappingModelAutomaticallyOption : @YES,
     NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"}
};
[persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]
于 2016-10-07T06:56:06.370 に答える