LiveCode LessonsLiveCode LessonsHow To - LiveCode Mobile TasksiOS 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 steps required 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 the 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

24 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

Roberto

We are now on iOS 14.4.1
Is the problem mentioned by Martini been solved?
Thanks

Roberto

I tested all this with iOS 14.4.2 and everything works fine.
I haven't found a similare lesson for Android. Does this means that it cannot be done?(associate a file with a standalone)

Roberto

I tried to publish on apple myApp with the Associated file type: I got back from apple the same message reported by Kim, about LSSupportsOpeningDocumentsInPlace.
The file handled by the App are custom files, that can be opened only by this app.
Problem is that I don't know where to plache the LSSupportsOpeningDocumentsInPlace, and also if it has to be "Yes" or "no, "True" or false.
Can you please explain?
Thanks

Matthias Rebbe

Roberto,
first of all LSSuportsOpeningDocumentsInPlace is a key and the value string is either TRUE if you want to allow the app to open the document in place or FALSE if you want to allow the app to open a copy of that document.
See also https://developer.apple.com/documentation/bundleresources/information_property_list/lssupportsopeningdocumentsinplace#details

To use LSSupportsOpeningDocumentsInPlace correct you have to use
<key>LSSupportsOpeningDocumentsInPlace</key>
<string>VALUE</string>
Replace VALUE either with FALSE or TRUE.

And if i am not totally wrong you can put it at the end of the additional Plist data which is created by the sample stack.
I've uploaded a modified version of the iOS-Plist-AdditionalData.livecode stack which supports now also LSSupportsOpeningDocumentsInPlace

Regarding your question how to do this in Android...
There is a workaround solution available on stackoverflow. I just skimmed that post, but maybe it gives you the needed information.
https://stackoverflow.com/questions/34300452/android-associate-app-with-custom-file-type

Roberto

Well, about the true/false you were correct. I was reading the apple documentation were it was stated:
"In iOS 11 and later, if both this key and the UIFileSharingEnabled key are YES, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a document browser. Users can open and edit these document in place."
Still don't know what happen if I mark it "false" instead of "true" (the docs don't really clarify this point).
Anyway, in order to make the LSSupportsOpeningDocumentsInPlace works, I had to put it inside the additional plist data, write before the last two lines:
LSSupportsOpeningDocumentsInPlace
VALUE

Matthias Rebbe

Roberto, so placing them above the last 2 lines of the additional data and publishing the app again did not return that 'error" message from Apple again?
That's good to know as i could not test publishing an app. I only could test on my iPhone and both versions (at the end and above the last 2 lines) worked here. So thanks for clarifying.

Regards,
Matthias

Roberto

Sorry but disregard what I said.
I couldn't have both the installing on my HD and the accepted Apple distribution.
In order to make it work, I set it to FALSE and move it after the additional plist (that means out side of the array and else. Just in any place in the basic level of the pList.
Anything else failed. The FALSE setting did not create any problem that i can see. But hey, I am still confused on iOS by the "document" folder, the "Files" folder and the Shared folder

Matthias Rebbe

Thanks Roberto.
So at least the updated stack 'iOS-Plist-AdditionalData.livecode' puts that at the correct place. ;)

Max

How can I show all file extensions inside a uidocumentbrowserviewcontroller? Apple states that it is possible by setting shouldShowFileExtensions to true but it doesn't seem to work. I searched through the intire web but I only found people complaining that it does not work (like here in the comments https://stackoverflow.com/questions/56915668/adding-file-extensions-to-ios-document-manager). Even example code from github did not work. Any ideas?

Panos Merakos

Hello Max,

Is that question about iOS apps made with LiveCode? LiveCode apps do not use a uidocumentbrowserviewcontroller.

Cheers,
Panos
--

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.