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 will need:

1. The stack iOS-Plist-AdditionalData.livecode

2. An iOS standalone of your project or a standalone of the sample stack FileLaunchTest.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 comma as column delimiter and the file extension .csv  or use the capitals.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 folder containing our stack.

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) in an editor and insert the additional data from your clipboard into it. The easiest option is to put the additional lines after the lines

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

You 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 capitals.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, the path to the file will be shown in the field and the content of the csv file will show up in the browser widget. 

But how is our app informed about the file?

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

  • The parameter pURL contains the complete path to the file
  • Put the pURL parameter into the "file" field
  • Set the URL parameter of the browser widget to pURL
on urlWakeUp pURL   
   put pURL into field "file"
   set the URL of widget "browser" to pURL
end urlWakeUp

14 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

Dr Christian Jacquelinet

It looks there is a typo error in generating:
LSSupportsOpeningDocumentsInPlace
instead of:
LSSupportsOpeningDocumentsInPlace

Kind regards,

Christian

Matthias Rebbe

Hi Christian,
thanks for pointing this out. I´ve uploaded a new version of the stack which should generate the part correctly now.

Kind regards,

Matthias

Christian Jacquelinet

Works fine now. The generated xml file comes with the right format.
With iOS 13.1, the csv doc does not launch
the app.
With iOS 12.4, the csv doc launches the app which crashes immediately ...

Paolo Martini

Hei! I generated the additional info.plist data through the attached stack (but this time for .pdf files) and inserted it into the suggested postition inside the info.plist. The plist inside the standalone contains now those added lines. The standalone is uploaded to my iPhone. I followed the way of testing suggested in the example, but, when I want to share the attached pdf in the email, my app still doesen't appear amongst the apps which can handle opening of PDF files. Any suggestion about what can I have done wrong?

Elanor Buchanan

Hi Paolo,

I tested here and can see the app in the list of apps available to open PDF files.

I added the following to the plist file, is this what you added?

CFBundleDocumentTypes


CFBundleTypeName
My CSV file
CFBundleTypeRole
Viewer
LSHandlerRank
Owner
LSItemContentTypes

com.livecode.csvtest

UTExportedTypeDeclarations

UTTypeConformsTo

public.data

UTTypeDescription
PDF Document
UTTypeIdentifier
com.livecode.csvtest
UTTypeTagSpecification

public.filename-extension
pdf
public.mime-type
application/pdf


LSSupportsOpeningDocumentsInPlace

Kind regards

Elanor

Paolo Martini

Hei Eleonor!
First of all: thankyou for your help!
Everything is alike but the following:
LSItemContentTypes

com.studiumactoris1.sf.pdf

and:

UTTypeIdentifier
com.studiumactoris1.sf.pdf

"com.studiumactoris1." is my identification as developer, "sf" is the name of the app I use in the certificate, and "pdf" is what it is.
I tried "your" version of the info.plist (com.studiumactoris1.sf without pdf at the end).
None of the 2 versions works on IOS 13.1.2 or 13.2 (app not appearing amongst the choices). IT WORKS in IOS 12.4.2 (app appears amongst the choices) BUT the app crashes. Best regards, Paolo

Paolo Martini

Hei Eleanor!
Have experimented little further with the installation of my app with the modified info.plist containing your code. I followed this steps on iPhone 6 with IOS 12.4.2 (the IOS where my app was appearing as a choice for opening of pdf):
1) action: I modified in the app the code of urlWakeUp to containing 1 line: "answer pURL"
2) action: installed my app containing your code in info.plist
result: appen is showing app amongst the choices of share button, BUT app crashes at opening
3) action: installed my app again (without neither deleting the previous installation or restarting the iphone) containing my original info.plist WITHOUT your code.
result: appen is STILL showing app amongst the choices of share button (???), BUT this time the app is not crashing AND it shows a dialog box with the pURL! Hope this can help you to sort out what is going on.
Best regards
Paolo

Elanor Buchanan

Hi Paolo

It looks like

LSSupportsOpeningDocumentsInPlace

is not required.

I have updated the lesson with a new steps and example files which I hope should fix these issues, this should also work for PDF files with the appropriate changes. Please do let us know how you get on when you have had a chance to try it.

Kind regards

Elanor

Paolo Martini

Hei Eleanor! Tested on both my iPhone 6 (IOS 12.4.2) and my iPhone X(R) (IOS 3.2 betatest), both for CSV and PDF files.
Result: your changings to the info.plist works now perfectly on the iphone 6 (for both PDF and CSV formats). Unfortunally it does not work on the iPhone X(R), the possiblity to open those formats with your test application does not appear amongst the possible choices of applications (scrolled down all the possibile choices without finding the app). I have being looking a little bit around on apple support forums and it seems this could be a general problem brought inn with the system IOS 13.1. If you find it useful I can send you or your team a screen shot/record of the iphone.
Kind regards
Paolo

Elanor Buchanan

Hi Paolo

I've looked into this a little and it seems to be a more general issue. We'll look into it further and update the lesson when we have a solution for iOS 13.1.

Kind regards

Elanor

Add your comment

E-Mail me when someone replies to this comment