ios4 - Copy SQLite Database from URL to Local Path -


what can use copy remote database local path?

success = [filemanager copyitematurl:dbpath topath:databasepath error: &error]; 

obviously above won't work. looking @ manual seems can copy path path or url url. i've seen example of myapp://path/to/documents/database.sql. i'm sorta confused. can possibly point me in right direction?

this i'm doing right now... it's not overwriting database or i'm doing things in wrong order. file couple of kbs also.

- (void)createdb { bool success; nserror *error;  nsdata *fetcheddata = [nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://www.dot.com/book/book.sqlite"]]; nsstring *documentspath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) lastobject]; nsstring *filepath = [documentspath stringbyappendingpathcomponent:@"book.sqlite"]; [fetcheddata writetofile:filepath atomically:yes]; nslog(@"%@", filepath);  nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *databasepath = [documentsdirectory stringbyappendingstring:@"book.sqlite"]; success = [filemanager fileexistsatpath:databasepath]; if(success)return; nsstring *dbpath = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"book.sqlite"]; success = [filemanager copyitematpath:dbpath topath:databasepath error: &error]; if(!success)     nsassert1(0, @"failed copy database. error: %@", [error localizeddescription]); } 

i see line,

nsstring *dbpath = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"book.sqlite"]; 

you trying db resources directory, code above downloads sqlite directly documents directory not resources (which not writable)

it fails because there no book.sqlite @ resources directory. don't need copy file since present in documents directory


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -