Open File in External App on iOS

2503
4
Jump to solution
03-13-2019 10:37 AM
ChristopherEby2
New Contributor III

I am trying to open a file in an external app on iOS but it's not working. I am using the Qt.openUrlExternally() function but I am getting errors that look like this:

This plugin does not support QPlatformServices::openDocument() for 'file:///private/var/mobile/Containers/Data/Application/F343D1DB-5FBC-488C-919A-6A6893944420/tmp/captureTest.jpg'.

The files can be of any type (.png, .jpg, .docx, .pdf, etc) and I have verified that they exist on the file system prior to running Qt.openUrlExternally(). My code works fine on Windows and only fails on iOS. I found this bug report for Qt: [QTBUG-42942] iOS: Implement QPlatformService::openDocument() - Qt Bug Tracker  

Based on that it appears that I need to write some C++ or native code to use the openDocument() function, which must be what Qt.openUrlExternally() calls to open things. However, since I am using AppStudio I can't take that approach. Is there an AppStudio workaround for this issue?

1 Solution

Accepted Solutions
ChristopherEby2
New Contributor III

The WebView approach kind of worked for images but not for PDFs or MS Office file formats so I abandoned that.  Next I looked into somehow tapping into the file sharing APIs of the iOS SDK but without access to writing any C++ code or including any C++ libraries the the approaches I found wouldn't work (https://blog.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app/ , Share from a QML app on iOS and AndroidUse the Felgo (formerly V-Play) Library to open a PDF). However, I did find that if I write my file to my apps Documents folder (AppFramework.standardPaths.writableLocation(StandardPaths.DocumentsLocation)) I should be able to see it in the Files app that comes with iOS 11+. However, to enable that I need to set the UIFileSharingEnabled key and the LSSupportsOpeningDocumentsInPlace key to true in the Info.plist file of my apps .ipa file (https://www.appcoda.com/files-app-integration). In AppStudio the File Sharing setting (capabilities.fileSharing in my appinfo.json file) allows me to set the UIFileSharingEnabled key to true but there was no AppStudio setting that corresponded to LSSupportsOpeningDocumentsInPlace. After some direct correspondence with ESRI they told me about a currently undocumented setting I could use. I added "interAppFileSharing": true to my appinfo.json file, built my application using the Cloud Make feature, and was able to see the attachments in the Files app after downloading them and writing them to the Documents folder. It's clunky but I'll popup a message every time someone taps on an attachment in my attachment list and tell them to switch to the Files app to view the attachment. That will satisfy my requirement for now.

View solution in original post

4 Replies
ErwinSoekianto
Esri Regular Contributor

Christoper, 

Have you tried using File, FileInfo, and FileFolder from AppStudio AppFramework? 

This is the doc has an example on the file.open() method, File QML Type | ArcGIS  

Thank you,

Erwin

0 Kudos
ChristopherEby2
New Contributor III

Erwin, yes I have. The File.open() method does not open the file in an eternal app. The docs aren't clear but it looks like it just loads a file into memory so that it can be read or edited by the AppStudio app. What I want to happen is similar to when you click on an address and it opens in Apple or Google Maps or clicking on a link that opens a browser (btw, Qt.openUrlExternally() works for that). Right now I'm investigating URL schemes as a potential solution but haven't found anything that works yet.

0 Kudos
ChristopherEby2
New Contributor III

No luck with URL schemes which really don't do what I want anyway (I don't want to have to manually figure out the file type and appropriate scheme, I'd like the OS to do that for me). I moved on to trying to open the file in a WebView. So far that works for images but not other file types like PDFs or MS Office files.

0 Kudos
ChristopherEby2
New Contributor III

The WebView approach kind of worked for images but not for PDFs or MS Office file formats so I abandoned that.  Next I looked into somehow tapping into the file sharing APIs of the iOS SDK but without access to writing any C++ code or including any C++ libraries the the approaches I found wouldn't work (https://blog.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app/ , Share from a QML app on iOS and AndroidUse the Felgo (formerly V-Play) Library to open a PDF). However, I did find that if I write my file to my apps Documents folder (AppFramework.standardPaths.writableLocation(StandardPaths.DocumentsLocation)) I should be able to see it in the Files app that comes with iOS 11+. However, to enable that I need to set the UIFileSharingEnabled key and the LSSupportsOpeningDocumentsInPlace key to true in the Info.plist file of my apps .ipa file (https://www.appcoda.com/files-app-integration). In AppStudio the File Sharing setting (capabilities.fileSharing in my appinfo.json file) allows me to set the UIFileSharingEnabled key to true but there was no AppStudio setting that corresponded to LSSupportsOpeningDocumentsInPlace. After some direct correspondence with ESRI they told me about a currently undocumented setting I could use. I added "interAppFileSharing": true to my appinfo.json file, built my application using the Cloud Make feature, and was able to see the attachments in the Files app after downloading them and writing them to the Documents folder. It's clunky but I'll popup a message every time someone taps on an attachment in my attachment list and tell them to switch to the Files app to view the attachment. That will satisfy my requirement for now.