ios - Device Directory -



ios - Device Directory -

so have app database. database in main bundle. need delete database , new 1 internet. far understood, can't delete bundle , add together new in need work device documents directory. don't know how create first database in documents directory without downloading internet. can help?

you need path of documents directory , need place database file there. need read/write operations in application copied database in app's document directory.

i utilize these methods create re-create of db in documents directory: need phone call method:

+(bool)copydbfiletodocumentsdirectory:(nsstring*)dbfilename overwrite:(bool)yesno

and need pass filename extension.

+(nsstring*)databaseabspath:(nsstring*)databasename existsindocumentsdirectory:(bool)existencestatus { bool success = no; nsstring *databasepath = nil; if(existencestatus)//documents directory { nsarray *documentpaths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdir = [documentpaths objectatindex:0]; databasepath = [documentsdir stringbyappendingpathcomponent:databasename]; } else //from bundle { nsarray *resourceseparatedbyextension = [databasename componentsseparatedbystring:@"."]; if([resourceseparatedbyextension count]<2) { nslog(@"problem database name or extension"); homecoming nil; } databasepath = [[nsbundle mainbundle] pathforresource:[resourceseparatedbyextension objectatindex:0] oftype:[resourceseparatedbyextension objectatindex:1]]; } nsfilemanager *filemanager = [nsfilemanager defaultmanager]; success = [filemanager fileexistsatpath:databasepath]; if(!success) { nslog(@"database file not exist @ path"); homecoming nil; } else { homecoming databasepath; } } +(bool)copydbfiletodocumentsdirectory:(nsstring*)dbfilename overwrite:(bool)yesno { nsstring *filepath = [mysqlitedb databaseabspath:dbfilename existsindocumentsdirectory:no]; nsarray *documentpaths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdir = [documentpaths objectatindex:0]; nsstring *databasepath = [documentsdir stringbyappendingpathcomponent:dbfilename]; if(filepath) { nserror *error = nil; if(!yesno && [[nsfilemanager defaultmanager] fileexistsatpath:databasepath]) { nslog(@"file exist @ path - instruction not overwrite"); homecoming yes; } else { [[nsfilemanager defaultmanager] removeitematpath:databasepath error:&error]; } error = nil; [[nsfilemanager defaultmanager] copyitematpath:filepath topath:databasepath error:&error]; if(!error) homecoming yes; nslog(@"error copying file :\n\n%@\n\nuserinfo:%@\n\nfailure reason: %@\n\n",[error localizeddescription],[[error userinfo] description],[error localizedfailurereason]); } homecoming no; }

ios cocoa-touch directory

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -