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:

  1. using webview

    nsstring *path = [[nsbundle mainbundle] pathforresource:@"document" oftype:@"pdf"]; nsurl *targeturl = [nsurl fileurlwithpath:path]; nsurlrequest *request = [nsurlrequest requestwithurl:targeturl]; [webview loadrequest:request]; 
  2. using uidocumentinteractioncontroller.

  3. have @ apple sample code zoomingpdfviewer


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -