Sunday, 15 June 2014

ios - CoreData: error: (14) on device, not in simulator -



ios - CoreData: error: (14) on device, not in simulator -

i error when running on device, not simulator (now).

i did same error on simulator , implemented solution thread: enter link description here

with code:

- (nspersistentstorecoordinator *)persistentstorecoordinator { if (__persistentstorecoordinator != nil) { homecoming __persistentstorecoordinator; } // nsurl *storeurl = [[self applicationdocumentsdirectory] urlbyappendingpathcomponent:@"engliah_famquiz.sqlite"]; //=== utilize database main bundle ===// nsurl *storeurl = [[nsbundle mainbundle] urlforresource:knewdb withextension:@"sqlite"]; // utilize source store - ensures don't accidentally write entities nsdictionary *options = [nsdictionary dictionarywithobject:[nsnumber numberwithbool:1] forkey:nsreadonlypersistentstoreoption]; // create sure wal mode core info not enabled options = @{ nssqlitepragmasoption : @{@"journal_mode" : @"delete"} }; <<< added line // nsdictionary *options = @{nsreadonlypersistentstoreoption : @yes, nssqlitepragmasoption : @{@"journal_mode" : @"delete"} }; nserror *error = nil; __persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:[self managedobjectmodel]];

this solved problem in simulator app crash on device next error:

2014-06-21 15:23:49.828 xxxx[30224:60b] effort add together read-only file @ path file:///var/mobile/applications/236047b5-0b0f-443d-abcf-dcaba0166713/xxxx.app/yyyyy.sqlite read/write. adding read-only instead. hard error in future; must specify nsreadonlypersistentstoreoption. 2014-06-21 15:23:49.838 xxxx[30224:60b] coredata: error: (14) i/o error database @ /var/mobile/applications/236047b5-0b0f-443d-abcf-dcaba0166713/xxxx.app/yyyy.sqlite. sqlite error code:14, 'unable open database file' 2014-06-21 15:23:49.845 xxxx[30224:60b] unresolved error error domain=nscocoaerrordomain code=256 "the operation couldn’t completed. (cocoa error 256.)" userinfo=0x16e48d80 {nsunderlyingexception=i/o error database @ /var/mobile/applications/236047b5-0b0f-443d-abcf-dcaba0166713/xxxx.app/yyyyy.sqlite. sqlite error code:14, 'unable open database file', nssqliteerrordomain=14}, { nssqliteerrordomain = 14; nsunderlyingexception = "i/o error database @ /var/mobile/applications/236047b5-0b0f-443d-abcf-dcaba0166713/xxxx.app/yyyy.sqlite. sqlite error code:14, 'unable open database file'";

in simulator there no error. also, first error new.

deployment target: 6.1

your code

nsdictionary *options = [nsdictionary dictionarywithobject:[nsnumber numberwithbool:1] forkey:nsreadonlypersistentstoreoption]; options = @{ nssqlitepragmasoption : @{@"journal_mode" : @"delete"} };

sets options dictionary containing nssqlitepragmasoption key only, not nsreadonlypersistentstoreoption key, because sec line overwrites dictionary assigned in first line.

what want is

nsdictionary *options = @{ nsreadonlypersistentstoreoption : @yes, nssqlitepragmasoption: @{@"journal_mode":@"delete"} };

to create options directory containing both keys.

in addition, have disable wal-mode when creating sqlite file bundled application.

the problem not occur in simulator because application directory read-write in simulator, read-only on device.

ios core-data xcode5

No comments:

Post a Comment