Open a document with uiwebview in IOS

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.