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.