Lloyd Hendricks
Lloyd Hendricks

Reputation: 11

Swift 3 - Generic File Opener

Good Day

I'm not new to swift but im new to the way swift handles file's etc... Ok ive done some extensive googling and stacking but I cant find a solution or an answer that matches my requirements.

We have a system that users can upload files on the web. The extensions are as follows:

.pdf .txt .doc .docx .bmp .jpeg .jpg .png .gif .tiff .tif .mp4 .avi .flv .mov .mwv .m4v .m4p .mpg .mpeg .mpv .3gp .xls .xlsx .xlsm .xlsb

Ok so Swift is downloading the files and saving to the local storage. I can retrieve the path once downloaded.

What I want to achieve is opening the file in the app and it must be able to do this according to the file type eg: image opens as image, video as vid ,etc

So my question is do i need to try cater for every file or is there a generic file opener that will open the file accordingly.

The file is downloaded through Alamofire's download function.

Any help would be greatly appreciated.

Upvotes: 1

Views: 794

Answers (1)

Dharma
Dharma

Reputation: 3013

There couple of things is available

Look at using the Quick Look Framework - Source

A Quick Look preview controller can display previews for the following items:

  1. iWork documents
  2. Microsoft Office documents (Office ‘97 and newer)
  3. Rich Text Format (RTF) documents
  4. PDF files
  5. Images
  6. Text files whose uniform type identifier (UTI) conforms to the public.text type (see Uniform Type Identifiers Reference)
  7. Comma-separated value (csv) files

WebView Supported File Formats are From Apple Documentation

In addition to HTML content, UIWebView objects can be used to display other content types, such as Keynote, PDF, and Pages documents.

From Apple Technical Q&A QA1630

  1. Excel (.xls)
  2. Keynote (.key.zip)
  3. Numbers (.numbers.zip)
  4. Pages (.pages.zip)
  5. PDF (.pdf)
  6. Powerpoint (.ppt)
  7. Word (.doc)

Upvotes: 1

Related Questions