IOS turns on third party program open file (Uidocumentinteractioncontroller)

Source: Internet
Author: User

The project has a download file function, download needs to be able to view, can not be for each type of file to write a view function bar.

The good news is that iOS has a uidocumentinteractioncontroller that can help you tune up the installed apps on your phone to see the files.


First, configure the Info.plist file to tell the system what types of files you need to use Uidocumentinteractioncontroller to open

You can also set UTI This property in your code, I haven't tried,

Plist inside can be a wave away, simple and convenient

Well, to summarize, that's pretty much it:

<key>CFBundleDocumentTypes</key>

<array>

<dict>

<key>CFBundleTypeName</key>

<string>com.myapp.common-data</string>

<key>LSHandlerRank</key>

<string>Default</string>

<key>LSItemContentTypes</key>

<array>

<string>com.microsoft.powerpoint.ppt</string>

<string>public.item</string>

<string>com.microsoft.word.doc</string>

<string>com.adobe.pdf</string>

<string>com.microsoft.excel.xls</string>

<string>public.image</string>

<string>public.content</string>

<string>public.composite-content</string>

<string>public.archive</string>

<string>public.audio</string>

<string>public.movie</string>

<string>public.text</string>

<string>public.data</string>

</array>

</dict>

</array>

Just stick to the info.plist.

Observe this agency agreement first: Uidocumentinteractioncontrollerdelegate

Then the Code section:

Get the downloaded file path 
nsstring *filepath = [[Lgdownloadmanager sharedinstance] getFilePathWithURL:fileModel.url];;
if (FilePath = = nil) return;
Convert to URL
nsurl *url = [Nsurl Fileurlwithpath:filepath];
    
if (URL) {
        
    SELF.DOCUMENTVC = [Uidocumentinteractioncontroller interactioncontrollerwithurl:url];
    [SELF.DOCUMENTVC setdelegate:self];
    BOOL CanOpen =  [SELF.DOCUMENTVC presentopeninmenufromrect:cgrectzero inView:self.view Animated:yes];
        
    Return no description There is no love fart that can open the file, friendly hints
    if (CanOpen = no) {
        Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "mention "message:@" did not find an application that could open the file "Delegate:nil cancelbuttontitle:@" otherbuttontitles:nil, nil];
        [Alert show];
    }

Landfills: SELF.DOCUMENTVC This object only uses in this place, I direct uidocumentinteractioncontroller *DOCUMENTVC = ... No, it's okay.

I did it from the beginning, and since I mentioned it, the result is still too young.

Why not?

DOCUMENTVC if it is not quoted, the braces are released, all become nil, and naturally cannot be bounced, and all of them must be referenced as a member of self to ensure that they are not released prematurely.





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.