LiveCode LessonsLiveCode LessonsHow To - LiveCode Mobile Tasks iOS TasksAssociating a file type / file extension with an LC iOS app

Associating a file type / file extension with an LC iOS app

Introduction

This lessons describes the needed steps to be able to open files (e.g. e-mail attachments)  in Livecode apps on iOS. In this lesson we dealing with a .csv file, but any file extension, even a custom one, can be opened when the info.plist contains the correct data.

Prerequisite

You´ll need:

1. The stack iOS-Plist-AdditionalData.livecode

2. An iOS standalone of your project or a standalone of the sample stack urlwakeup.livecode

Note 1: If you are using the sample stack, then please adjust the iOS settings (Internal App ID and Profile)
Note 2: If you are using your own stack, then please add the script  from step  But how is our app informed about the file? to your stack

3. A text file with TAB as column delimiter and the file extension .csv  or use the sample.csv file

Copy the info.plist from iOS app bundle

Right click on you iOS app bundle and select Show Package Contents

Move or copy the file info.plist  to another folder. In our  example  we move it to the Desktop folder.

Create the additional needed data

Open the the stack iOS-Plist-AdditionalData.livecode

Fill all fields with needed information (see annotations)

  1. enter a name/description e.g. My CSV File
  2. enter your internal App ID  + .csv e.g. com.mycompany.myapp.csv (see annotation 9)
  3. enter a description e.g. CSV Document
  4. enter your internal App ID + .csv e.g. com.mycompany.myapp.csv (see annotation 9)
  5. enter the extension, e.g. csv
  6. press the magnifier glass to fetch the mime type for the entered extension
  7. select the method for opening the file
  8. press button create the....
  9. press the Clipboard Icon to copy the created data to the clipboard

 

Add the additional data to the info.plist

1. Open the info.plist file (the one you´ve copied/moved  to the Desktop) in an editor and insert  the additional data from your clipboard into it. The best is to put the additonal lines after the lines

<key>CFBundleSignature</key>
<string>????</string>

You´ll should find them around line 19-20 or so.

2. Save the file info.plist

Modify standalone settings for your iOS app

1. In Standalone Settings for your iOS app go to the Copy Files pane and add the custom info.plist file

2. Save the stack

 

First Test

1a. Create a new standalone app of your stack and install it on your device

or

1b.  Connect your iOS device to your Mac, select your device in LC IDE under Development/Test Target and press the Test button/icon in IDE menu bar

2.  send an email to yourself and attach the sample.csv file or  any other text file with .csv file extension and open that email on your iOS device.

3. If all went well then you should see your Livecode iOS app (maybe among others) in the list of Apps in which the .csv can be opened.

4. Select your iOS app. Your app should open and the content of the csv file should show up in the table field.

5. Pressing the button Show files in Documents folder lists all files of the documents folder, in our case there should be only the sample.csv or the file you´ve attached to that email.

 

But how is our app informed about the file?

To inform our app about the file we make use of  the message urlWakeUp.

In the following sample code we are saving the .csv file to the documents folder  and also we are putting the content of the file into the field "table field"

The parameter pURL contains the complete path to the file including the prefix "file:" or "binfile:". So as soon as we have this path, we can do everything with that file or its content.

 

on urlWakeUp pURL
   
   mobileBusyIndicatorStart "square", "Importing"
   
   if pURL  contains ".csv"  
   then 
      -- save the file to the documents folder
      set the itemdelimiter to slash
      put url pURL into url ("file:"&specialfolderpath("documents")&"/"&item (the number of items of pURL) of pURL)
      
      -- Here we grab the content of the .csv file and put it into our table field
      put URL pURL into fld "table field"
   end if

   mobileBusyIndicatorStop
   
   answer "Done"
end urlWakeUp

4 Comments

Kim

Thanks, but I couldn't get iOS-PList-AdditionalData to work. When I press the "Create the additional PList data", it gives me a "Please fill out all fields" error message. I can't see any more fields to fill out ;-) I've tried inputting both data for my app & the example data given in the app's field headings. I've tried on MacOS & Windows. LC 9.0.4.

Elanor Buchanan

Hi Kim

There was an issue with the iOS-Plist-AdditionalData stack, I have uploaded a new version which should acknowledge that you have filled in all the fields :)

Thanks for bringing this to our attention.

Kind regards

Elanor

Kim

Hi Elanor. Thanks for the earlier fix. FYI - I tried promoting to App Store Connect and got the following warning. I've got it sorted, but you MIGHT want to integrate into lesson.

WARNING ITMS-90737: "Missing Document Configuration. By declaring the CFBundleDocumentTypes key in your app, you've indicated that your app is able to open documents. Please set the UISupportsDocumentBrowser key to "YES" if your app uses a UIDocumentBrowserViewController. Otherwise, set the LSSupportsOpeningDocumentsInPlace key in the Info.plist to "YES" (recommended) or "NO" to specify whether the app can open files in place. All document-based apps must include one of these configurations. For more information, visit https://developer.apple.com/document-based-apps/."

Elanor Buchanan

Hi Kim

Thats really helpful, thank you. We'll get the lesson updated with this information.

Kind regards

Elanor

Add your comment

E-Mail me when someone replies to this comment