ios - Load file to application local storage -
is there ability load files documents, articles server , store them in application local storage using filemanager? , how users can read these files? have access folder?
follow these steps downloading , saving file in nsdocumentdirectory
// determine local file path nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *filepath = [nsstring stringwithformat:@"%@/%@", [paths objectatindex:0],@"filename.doc"]; //it file type // download , write file nsurl *url = [nsurl urlwithstring:@"http://www.filepathfromserverlocation.com"]; //and write file nsdata *urldata = [nsdata datawithcontentsofurl:url]; [urldata writetofile:filepath atomically:yes];
this way file save @ filepath
, u can use in future whatever way u like.
opening file in ios:
using
webview
nsstring *path = [[nsbundle mainbundle] pathforresource:@"document" oftype:@"pdf"]; nsurl *targeturl = [nsurl fileurlwithpath:path]; nsurlrequest *request = [nsurlrequest requestwithurl:targeturl]; [webview loadrequest:request];
using
uidocumentinteractioncontroller
.have @ apple sample code zoomingpdfviewer
Comments
Post a Comment