xml - How to download file and save in local iphone application? -
i have locally saved 1 xml file , showing details using nsxmlparser(which stored in resource folder). but, want download new xml url(from client side) , need store new xml file in local , need delete existing 1 application. how can this? suggestions? there sample code/project reference? please me. reading poor english. advance.
although u can delete file yr resource directory , save new 1 way perform file operation on app diretories document directory or cache directory.
first u save yr xml file app resource cache directory access file there.and u can remove file resource directory ,its no longer needed. new file available in internet first remove old 1 cache , add new 1 cache directory.
whole thing follows:-
//get cachedirectory path nsarray *imagepaths = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes); nsstring *cachdirectory = [[nsstring alloc] initwithstring:[imagepaths objectatindex:0]]; //first save file resource directory app's cache directory nsstring * path = [[nsbundle mainbundle] pathforresource:@"fileinresource" oftype:@"xml"]; nsdata *filedata = [nsdata datawithcontentsoffile:path]; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsstring *savename = [cachdirectory stringbyappendingpathcomponent:@"mynewfile.xml"]; [filemanager createfileatpath:savename contents:filedata attributes:nil]; //remove file resource directory [filemanager removeitematpath:path error:nil]; //new file internet avilable following:first remove old file cache [filemanager removeitematpath:cachdirectory error:nil]; //save new file internet nsdata *newfiledata=[nsdata datawithcontentsofurl:[nsurl urlwithstring:myxmlurlstringpath]]; [filemanager createfileatpath:savename contents:newfiledata attributes:nil];
Comments
Post a Comment