For iOS users, Corona SDK now offers the QuickLook Plugin which allows your app to show various document files, including:

  • iWork documents
  • Microsoft Office documents (Office97™ and newer)
  • Rich Text Format (RTF) documents
  • PDF files
  • Images
  • Text files whose Uniform Type Identifier (UTI) conforms to the public.text type
  • Comma-separated value (csv) files

Setting Up

If you’re a Pro or Enterprise subscriber, you can include this plugin in your project by adding the following to your build.settings file:

Inside the app, the QuickLook plugin is called via native.showPopup(). It’s good practice to test that the device can show the popup by calling native.canShowPopup() in advance.

Assuming the device is capable of showing it, just create a table of parameters and pass it to the native.showPopup() API:

As you can see, the files table within the popupOptions table contains a list of files. This example illustrates how to show files in a sub-directory — in this case, files in the system.ResourceDirectory. If you are downloading files, or creating them yourself, you would likely access them in system.DocumentsDirectory or system.CachesDirectory.

In some cases, you will only need to show one file, but the plugin gives you the option of showing several files. It defaults to the first file in the list, but you can specify an alternate file by setting the startIndex parameter.

Callback Listener

The QuickLook plugin also features an optional callback parameter which lets you know when the user is done viewing the document and what document was viewed last. Just specify your listener function as the listener parameter and handle the results as you see fit. For example:

Limitations

As with the Pasteboard Plugin, the QuickLook Plugin is currently only available on iOS to Corona Pro or Enterprise subscribers. You must also build the app for an actual device to test your QuickLook functionality.

Original article: 

Tutorial: Introducing the QuickLook Plugin (iOS)