Using the system's uiwebview on the iPad to open a document is convenient and easy to use, and there are many types of documents that can be opened. The disadvantage is that there is no editing function, and you can only view it after opening it.
All of the following tests are on the iPad and are not necessarily applicable on the iPhone!
Supported document types: PDF, Doc, docx, xls, XLSX, PPT, pptx, and txt (supported by tests). Common image formats should also be supported, but not tested.
The method is as follows:
1. Obtain the nsurl object through the file storage path;
2. Construct the nsurlrequest object using nsurl;
3. After passing the nsurlrequest to a uiwebview, uiwebview automatically opens the file.
CodeAs follows:
Nsstring * filepath = @ "*********"; nsurl * fileurl = [nsurl fileurlwithpath: filepath]; nsurlrequest * request = [nsurlrequest requestwithurl: fileurl]; [webview loadrequest: request];
You can enable the content displayed by webview to automatically fill the entire webview.