无法保存到数据存储:无法完成操作。 (可可错误133020) [英] Failed to save to data store: The operation couldn’t be completed. (Cocoa error 133020.)

查看:138
本文介绍了无法保存到数据存储:无法完成操作。 (可可错误133020)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发相当复杂的应用程序与巨大的同步程序的网络iphone和网络服务器。我没有麻烦添加记录,直到我在separete线程中运行同步过程,它会更新serwer上的数据,并将他们发送回iphone。但是在此过程之后,插入新数据会导致错误,例如:

  2011-01-07 12:49:10.722应用程序[1987:207]无法保存到数据存储:操作无法完成。 (Cocoa错误133020.)
2011-01-07 12:49:10.724 App [1987:207] {
conflictList =(
NSMergeConflict(0x5ac1ea0)for NSManagedObject(0x5a2d710)with objectID '0x5a27080< x-coredata:// E82E75ED-96DB-4CBF-9D15-9CC106AC0052 / uzytkownicy / p10>'with oldVersion = 9 and newVersion = 21 and old object snapshot = {\\\
adres = \< null> ; \; \\\
haslo = xxxxxxxxxxxxxxxxxxxxxx; \\\
\id_uzytkownika\= 3; \\\
imie = Jan; \\\
\kod_jednorazowy\= 0; \\\
komorka = \< null> \; \\\
login = nowakjan; \\\
nazwisko = Nowak; \\\
pesel = 0; \\\
rodzaj = 2; \\\
\stan_konta\ 0; \\\
telefon = \< null> \; \\\
\uzytkownicy_uczniowie\= \< null> \; \\\
\zmienna_losowa\ = 8G9e1; \\\
}和新的缓存行= {\\\
adres = \< null> \; \\\
haslo = xxxxxxxxxxxxxxxxxxxxxx; \\\
\id_uzytkownika\= 3; \\ n imie = Jan; \\\
\kod_jednorazowy\= 0; \\\
komorka = \< null> \; \\\
login = nowakjan; \\\
nazwisko = Nowak; \\ n pesel = 0; \\\
rodzaj = 2; \\\
\stan_konta\= 0; \\\
telefon = \< null> \; \\\
\uzytkownicy_uczniowie\\ NSManagedObject(0xcd05950)的NSMergeConflict(0xd266990),其中objectID为0 0x5a453b0< x-coredata:// E82E75ED-96DB-4CBF-9D15-9CC106AC0052 / uczniowie / p125>'with oldVersion = 5 and newVersion = 10 and old object snapshot = {\\\
adres = \Warszawa; ul。 Lwowska 32 \; \\\
\data_urodzenia\= \1997-02-01 23:00:00 + 0000 \; \\\
dysfunkcje = \\; \ n email = \< null> \; \\\
frekwencja = 0; \\\
\id_ucznia\= 86; \\\
imie2 = Marian; \\\
\imie_ucznia \ = \S\\U0142awomir\; \\\
klasa = \0x5a47820< x-coredata:// E82E75ED-96DB-4CBF-9D15-9CC106AC0052 / zespoly / p9& \ n komorka = \< null> \; \\\
\miejsce_urodzenia\= Warszawa; \\\
\nazwisko_ucznia\= \S \\U0142awek\\ \\; \\\
\numer_ewidencyjny\= 20; \\\
opiekun1 = \Mariusz S \\U0142awek\; \\\
opiekun2 = \\; \\\
pesel = 97020298919; \\\
plec = 1; \\\
telefon = 890000002; \\\
\uzytkownicy_uczniowie\= \< null> \; \\\
\web_klasa \ = 50; \\\
}和新的缓存行= {\\\
adres = \Warszawa; ul。 Lwowska 32 \; \\\
\data_urodzenia\= \1997-02-01 23:00:00 + 0000 \; \\\
dysfunkcje = \\; \ n email = \< null> \; \\\
frekwencja = 0; \\\
\id_ucznia\= 86; \\\
imie2 = Marian; \\\
\imie_ucznia \ = \S\\U0142awomir\; \\\
klasa = \0x5a8e7c0 \miejsce_urodzenia\= Warszawa; \\\
\nazwisko_ucznia\= \S \\U0142awek\\ \\; \\\
\numer_ewidencyjny\= 20; \\\
opiekun1 = \Mariusz S \\U0142awek\; \\\
opiekun2 = \\; \\\
pesel = 97020298919; \\\
plec = 1; \\\
telefon = 890000002; \\\
\uzytkownicy_uczniowie\= \< null> \; \\\
\web_klasa \ = e-e-96DB-4CBF-9D15-9CC106AC0052 / przedmioty / p12>的NSManagedObject(0x5a44480)的= 50; \ n},
NSMergeConflict(0xd2669b0) with oldVersion = 7 and newVersion = 15 and old object snapshot = {\\\
\id_przedmiotu\= 1; \\\
\nazwa_przedmiotu\= Historia; \\\
\skrot_nazwy \ = Hist; \\\
}和新的缓存行= {\\\
\id_przedmiotu\= 1; \\\
\nazwa_przedmiotu\= Historia; \\\
\skrot_nazwy \ = Hist; \\\
}
);
}



我一直在寻找任何解决方案,但没有运气。

预先感谢您提供任何有用的帮助。






 code> oceny_ucznia * nowaOcenka =(oceny_ucznia *)[NSEntityDescription insertNewObjectForEntityForName:@oceny_uczniainManagedObjectContext:[Factory getVar:@context]]; 

nowaOcenka.przedmiot =(przedmioty *)[Factory getVar:@cPrzedmiot];
nowaOcenka.web_przedmiot = [NSNumber numberWithInt:[((przedmioty *)[Factory getVar:@cPrzedmiot])id_przedmiotu intValue]];
nowaOcenka.nauczyciel =(uzytkownicy *)[Factory getVar:@cNauczyciel];
nowaOcenka.web_nauczyciel = [NSNumber numberWithInt:[((uzytkownicy *)[Factory getVar:@cNauczyciel])id_uzytkownika intValue]];
nowaOcenka.lekcja =(lekcje *)[Factory getVar:@cLekcja];
nowaOcenka.uczen = uczeniek;
nowaOcenka.web_uczen = [NSNumber numberWithInt:[uczeniek.id_ucznia intValue]];
nowaOcenka.czas_wpisania = [NSDate date];

if(grupka!= nil){
nowaOcenka.grupa = grupka;
nowaOcenka.web_grupa = [NSNumber numberWithInt:[grupka.id_grupy_ocen intValue]];
nowaOcenka.kolumna = [NSNumber numberWithInt:([kolumienka intValue] +1)];
nowaOcenka.grupa.czas_wpisania = [NSDate date];
} else {
int wartoscOceny = [[Factory getVar:@cSemestr] intValue];
wartoscOceny + =([kolumienka intValue] == 0)? 2:0;
nowaOcenka.koncowa = [NSNumber numberWithInt:wartoscOceny];
}

nowaOcenka.wartosc = [NSNumber numberWithFloat:[[((slownik_ocen *)[self.slownikOcen objectAtIndex:[ocena selectedRowInComponent:0]])wartosc_liczbowa] floatValue]];
nowaOcenka.ocena = [NSString stringWithFormat:@%@,[((slownik_ocen *)[self.slownikOcen objectAtIndex:[ocena selectedRowInComponent:0]])ocena_opis]];
nowaOcenka.semestr = [NSNumber numberWithInt:[[Factory getVar:@cSemestr] intValue]];

((lekcje *)[Factory getVar:@cLekcja])。czas_wpisania = [NSDate date];

NSError * error;
if(![[getVar:@context] save:& error]){
NSLog(@无法保存到数据存储:%@,[error localizedDescription]);
NSArray * detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors!= nil&& [detailedErrors count]> 0){
for(NSError * detailedError in detailedErrors){
NSLog(@DetailedError:%@ [detailedError userInfo]);
}
}
else {
NSLog(@%@,[error userInfo]);
}
}

工厂类描述这里,但是在同步过程之后,可能存在未精确刷新的上下文的问题。 / p>

解决方案

根据:



http://developer.apple.com/library/ios/ #documentation / cocoa / Reference / CoreDataFramework / Miscellaneous / CoreData_Constants / Reference / reference.html



该错误是 NSManagedObjectMergeError


错误代码表示合并
策略失败 - 核心数据无法
完成合并。


NSError对象可能能够帮助解码此错误。您可以发布您用来插入新数据的代码吗?


I am working on quite complex app with huge sync procedure beetwen iphone and web server. I have no troubles with adding records, until I run sync procedure in separete thread, and It will update data on serwer, and send them back to iphone. But after this procedure, inserting new data cause error, such as this:

2011-01-07 12:49:10.722 App[1987:207] Failed to save to data store: The operation couldn’t be completed. (Cocoa error 133020.)
2011-01-07 12:49:10.724 App[1987:207]   {
    conflictList =     (
        "NSMergeConflict (0x5ac1ea0) for NSManagedObject (0x5a2d710) with objectID '0x5a27080 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/uzytkownicy/p10>' with oldVersion = 9 and newVersion = 21 and old object snapshot = {\n    adres = \"<null>\";\n    haslo = xxxxxxxxxxxxxxxxxxxxxx;\n    \"id_uzytkownika\" = 3;\n    imie = Jan;\n    \"kod_jednorazowy\" = 0;\n    komorka = \"<null>\";\n    login = nowakjan;\n    nazwisko = Nowak;\n    pesel = 0;\n    rodzaj = 2;\n    \"stan_konta\" = 0;\n    telefon = \"<null>\";\n    \"uzytkownicy_uczniowie\" = \"<null>\";\n    \"zmienna_losowa\" = 8G9e1;\n} and new cached row = {\n    adres = \"<null>\";\n    haslo = xxxxxxxxxxxxxxxxxxxxxx;\n    \"id_uzytkownika\" = 3;\n    imie = Jan;\n    \"kod_jednorazowy\" = 0;\n    komorka = \"<null>\";\n    login = nowakjan;\n    nazwisko = Nowak;\n    pesel = 0;\n    rodzaj = 2;\n    \"stan_konta\" = 0;\n    telefon = \"<null>\";\n    \"uzytkownicy_uczniowie\" = \"<null>\";\n    \"zmienna_losowa\" = 8G9e1;\n}",
        "NSMergeConflict (0xd266990) for NSManagedObject (0xcd05950) with objectID '0x5a453b0 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/uczniowie/p125>' with oldVersion = 5 and newVersion = 10 and old object snapshot = {\n    adres = \"Warszawa; ul. Lwowska 32\";\n    \"data_urodzenia\" = \"1997-02-01 23:00:00 +0000\";\n    dysfunkcje = \"\";\n    email = \"<null>\";\n    frekwencja = 0;\n    \"id_ucznia\" = 86;\n    imie2 = Marian;\n    \"imie_ucznia\" = \"S\\U0142awomir\";\n    klasa = \"0x5a47820 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/zespoly/p9>\";\n    komorka = \"<null>\";\n    \"miejsce_urodzenia\" = Warszawa;\n    \"nazwisko_ucznia\" = \"S\\U0142awek\";\n    \"numer_ewidencyjny\" = 20;\n    opiekun1 = \"Mariusz S\\U0142awek\";\n    opiekun2 = \" \";\n    pesel = 97020298919;\n    plec = 1;\n    telefon = 890000002;\n    \"uzytkownicy_uczniowie\" = \"<null>\";\n    \"web_klasa\" = 50;\n} and new cached row = {\n    adres = \"Warszawa; ul. Lwowska 32\";\n    \"data_urodzenia\" = \"1997-02-01 23:00:00 +0000\";\n    dysfunkcje = \"\";\n    email = \"<null>\";\n    frekwencja = 0;\n    \"id_ucznia\" = 86;\n    imie2 = Marian;\n    \"imie_ucznia\" = \"S\\U0142awomir\";\n    klasa = \"0x5a8e7c0 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/zespoly/p9>\";\n    komorka = \"<null>\";\n    \"miejsce_urodzenia\" = Warszawa;\n    \"nazwisko_ucznia\" = \"S\\U0142awek\";\n    \"numer_ewidencyjny\" = 20;\n    opiekun1 = \"Mariusz S\\U0142awek\";\n    opiekun2 = \" \";\n    pesel = 97020298919;\n    plec = 1;\n    telefon = 890000002;\n    \"uzytkownicy_uczniowie\" = \"<null>\";\n    \"web_klasa\" = 50;\n}",
        "NSMergeConflict (0xd2669b0) for NSManagedObject (0x5a44480) with objectID '0x5a47830 <x-coredata://E82E75ED-96DB-4CBF-9D15-9CC106AC0052/przedmioty/p12>' with oldVersion = 7 and newVersion = 15 and old object snapshot = {\n    \"id_przedmiotu\" = 1;\n    \"nazwa_przedmiotu\" = Historia;\n    \"skrot_nazwy\" = Hist;\n} and new cached row = {\n    \"id_przedmiotu\" = 1;\n    \"nazwa_przedmiotu\" = Historia;\n    \"skrot_nazwy\" = Hist;\n}"
    );
}

I've been looking for any solution but without luck.

Thank You in advance for any usefull help.


    oceny_ucznia *nowaOcenka = (oceny_ucznia *)[NSEntityDescription insertNewObjectForEntityForName:@"oceny_ucznia" inManagedObjectContext:[Factory getVar:@"context"]];

    nowaOcenka.przedmiot                = (przedmioty *) [Factory getVar:@"cPrzedmiot"];
    nowaOcenka.web_przedmiot            = [NSNumber numberWithInt:[((przedmioty *)[Factory getVar:@"cPrzedmiot"]).id_przedmiotu intValue]];
    nowaOcenka.nauczyciel               = (uzytkownicy *)[Factory getVar:@"cNauczyciel"];
    nowaOcenka.web_nauczyciel           = [NSNumber numberWithInt:[((uzytkownicy *)[Factory getVar:@"cNauczyciel"]).id_uzytkownika intValue]];
    nowaOcenka.lekcja                   = (lekcje *)[Factory getVar:@"cLekcja"];
    nowaOcenka.uczen                    = uczeniek;
    nowaOcenka.web_uczen                = [NSNumber numberWithInt:[uczeniek.id_ucznia intValue]];
    nowaOcenka.czas_wpisania            = [NSDate date];

    if ( grupka != nil ) {
        nowaOcenka.grupa                = grupka;
        nowaOcenka.web_grupa            = [NSNumber numberWithInt:[grupka.id_grupy_ocen intValue]];
        nowaOcenka.kolumna              = [NSNumber numberWithInt:([kolumienka intValue]+1)];
        nowaOcenka.grupa.czas_wpisania  = [NSDate date];
    } else {
        int wartoscOceny                = [[Factory getVar:@"cSemestr"] intValue];
        wartoscOceny                   += ( [kolumienka intValue]==0 ) ? 2 : 0;
        nowaOcenka.koncowa              = [NSNumber numberWithInt:wartoscOceny];
    }

    nowaOcenka.wartosc                  = [NSNumber numberWithFloat:[[((slownik_ocen *)[self.slownikOcen objectAtIndex:[ocena selectedRowInComponent:0]]) wartosc_liczbowa] floatValue]];
    nowaOcenka.ocena                    = [NSString stringWithFormat:@"%@",[((slownik_ocen *)[self.slownikOcen objectAtIndex:[ocena selectedRowInComponent:0]]) ocena_opis]];
    nowaOcenka.semestr                  = [NSNumber numberWithInt:[[Factory getVar:@"cSemestr"] intValue]];

    ((lekcje *)[Factory getVar:@"cLekcja"]).czas_wpisania = [NSDate date];

    NSError* error;
if(![[Factory getVar:@"context"] save:&error]) {
        NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
        NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
        if(detailedErrors != nil && [detailedErrors count] > 0) {
            for(NSError* detailedError in detailedErrors) {
                NSLog(@"  DetailedError: %@", [detailedError userInfo]);
            }
        }
        else {
            NSLog(@"  %@", [error userInfo]);
        }
}

Factory class is described here, but probablly there is a problem with a context that is not refreshed accurately after sync procedure.

解决方案

According to:

http://developer.apple.com/library/ios/#documentation/cocoa/Reference/CoreDataFramework/Miscellaneous/CoreData_Constants/Reference/reference.html

that error is NSManagedObjectMergeError:

Error code to denote that a merge policy failed—Core Data is unable to complete merging.

The NSError object may be able to help in decoding this error. Can you post the code you are using to insert the new data?

这篇关于无法保存到数据存储:无法完成操作。 (可可错误133020)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆