Associating a file type / file extension with an LC iOS app
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.
1. The stack iOS-Plist-AdditionalData.livecode. Get your copy here from Livecodeshare.
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. press button create the....
8. 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
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
1a. Create a new standalone app of your stack and install it on your device
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