iOS opens Word document, PPT, etc. in project summary

Source: Internet
Author: User

Recently encountered in project development to download the document preview requirements of the attachment, here to summarize my implementation method, this article will be accompanied by the demo I wrote

Here I summarize three implementation methods (1) with WebView Preview (2) through Uidocumentinteractioncontroller implementation jump (3) Apply the Quick Look system framework, the following in turn describes the implementation of each method

First of all, use webview This is more commonly used, do not do too much explanation, the code is as follows:

_webview = [[UIWebView alloc]initwithframe:self.view.bounds];    _webview.delegate = self;    Nsurlrequest *request = [Nsurlrequest requestwithurl:_url1];    [_webview loadrequest:request];    [_webview Setscalespagetofit:yes];    [Self.view Addsubview:_webview];

The second application Uidocumentinteractioncontroller implementation method is as follows:

Initialize the object first, and set the popup mode _documentint = [Uidocumentinteractioncontroller interactioncontrollerwithurl:_url2];    [_documentint setdelegate:self];    [_documentint Presentpreviewanimated:yes];    [_documentint presentoptionsmenufromrect:cgrectmake (0, 0, 375, 667) InView:self.view  animated:yes];// Then implement the appropriate proxy method-(uiviewcontroller*) Documentinteractioncontrollerviewcontrollerforpreview: ( uidocumentinteractioncontroller*) controller{    return self;} -(uiview*) Documentinteractioncontrollerviewforpreview: (uidocumentinteractioncontroller*) controller{    return Self.view;} -(CGRect) Documentinteractioncontrollerrectforpreview: (uidocumentinteractioncontroller*) controller{        return Self.view.frame;} Called when the "done" button of the preview window is clicked-(void) Documentinteractioncontrollerdidendpreview: (uidocumentinteractioncontroller*) _ controller{    [_documentint dismisspreviewanimated:yes];}

The third kind of quick look, with this method needs to import the Quicklook.framework framework, the code is as follows:

Initialize object Qlpreviewcontroller *myqlpreviewcontroller = [[Qlpreviewcontroller alloc]init];    Myqlpreviewcontroller.delegate =self;    Myqlpreviewcontroller.datasource =self;    [Myqlpreviewcontroller setcurrentpreviewitemindex:0];    [Self Presentviewcontroller:myqlpreviewcontroller animated:yes completion:nil];//Implementing Proxy Method-(Nsinteger) Numberofpreviewitemsinpreviewcontroller: (Qlpreviewcontroller *) controller{    return 1;} -(ID) Previewcontroller: (Qlpreviewcontroller *) controller previewitematindex: (nsinteger) index{    //    NSString *filename = [self.listdic objectforkey:@ "FileName"];    nsstring* Path = [Nshomedirectory () stringbyappendingpathcomponent:[nsstringstringwithformat:@ "Documents/%@ ", FileName]];        return _url3;    }

Demo:https://github.com/zk1947/zkdemoall

iOS opens Word document, PPT, etc. in project summary

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.