how do you export a file out of iOS when using cordova file plugin? - ios

I'm using https://github.com/apache/cordova-plugin-file on an iOS device and I'm attempting to write files. I can write files ok but according to the iOS file system layout, all of these locations where I write are private.
I'm guessing this is due to Apple's sandbox security model so that each app can only see files within its own bundle. This is different on Android where the cordova.file.externalRootDirectory location is NOT private.
My question is: How do you export this file out of an iOS device?
The file that I'm writing contain a long list of GPS locations captured by the Cordova app I'm running. I can see the file in XCode, under devices, and export the whole container in order to view the file. But there has to be a better way to transfer the file out. Is it possible to transfer a Cordova generated file out of an iOS device to the computer -- maybe through iTunes or iCloud?
I've also tried using cordova.file.syncedDataDirectory and I can write files to that location just fine. But the file doesn't appear in my iCloud account.

You have to use itunes file sharing
File-Sharing Support
File-sharing support lets apps make user data files available in
iTunes 9.1 and later. An app that declares its support for file
sharing makes the contents of its /Documents directory available to
the user. The user can then move files in and out of this directory as
needed from iTunes. This feature does not allow your app to share
files with other apps on the same device; that behavior requires the
pasteboard or a document interaction controller object.
To enable file sharing for your app, do the following:
Add the UIFileSharingEnabled key to your app’s Info.plist file, and set the value of the key to YES.
Put whatever files you want to share in your app’s Documents directory.
When the device is plugged into the user’s computer, iTunes displays a File Sharing section in the Apps tab of the selected
device.
The user can add files to this directory or move files to the desktop.
Apps that support file sharing should be able to recognize when files
have been added to the Documents directory and respond appropriately.
For example, your app might make the contents of any new files
available from its interface. You should never present the user with
the list of files in this directory and ask them to decide what to do
with those files.
So, add the UIFileSharingEnabled to your info.plist and set it to YES
https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/CoreServicesLayer/CoreServicesLayer.html#//apple_ref/doc/uid/TP40007898-CH10-SW30

#jcesarmobile's answer helped me track down that I needed to enable file sharing in iOS. After confirming that I can enable file sharing by modifying the info.plist file in XCode, I found out that you could directly set UIFileSharingEnabled in the config.xml file but it's a bit more tricky because it's not a standard preference.
<gap:config-file platform="ios" parent="UIFileSharingEnabled" mode="replace">
<true/>
</gap:config-file>
After putting this in my config.xml file, it worked.
This is noted in the PhoneGap documentation, but I'll admit that it was really buried and a bit difficult to find.
http://docs.build.phonegap.com/en_US/configuring_config_file_element.md.html#Config%20File%20Elements

Related

How to Flutter write files to iOS iPhone "Find on my phone" Folder

My goal is to allow my app user write and read files created by my app. For example, write and then allow the user to email a .CSV file of data, or a .GPX file of location data. And on the other end, import a file back into my application.
I have successfully deployed an Android version of my app (Plant List GPS) which uses Flutter plugin path_provider 1.6.10. On Android, I successfully use external directories, but this external directories solution is not available/allowed for iOS. I find on iOS I can create subfolders and write to the getApplicationDocumentsDirectory, but when I try to find/read that file from a file picker solution, it cannot be seen. I understand this is proper behavior to protect sensitive app files in this folder location.
I also understand that iOS has the concept of an app Sandbox and appreciate its objectives. I'm not trying to defeat it, but find a way to access/use it in my Flutter app. I have played around in writing test data files to various places on the iOS file system using the iPhone 11 simulator on my MacBook, but can not get any file to appear in the phone "Find on my phone" dialog.
Any help in solution approach or technique is appreciated.
I think you need to add both the keys into info.plist, and then files from your app directory will be visible on Files app!
LSSupportsOpeningDocumentsInPlace
UIFileSharingEnabled

How to Save video file to iOS Files App using UIDocumentInteractionController

I want to write one or multiple mov/mp4 files to iOS Files App but can not find how to do it with UIDocumentInteractionController. Looking for a sample code to copy files to a subfolder of my app in iOS files app using UIDocumentInteractionController. See sample screenshot to understand what I want.
You will first need to create a File Provider extension for your app if you are storing the files remotely.
If they are only being stored locally on device you can achieve this by (in the Info.plist) either setting the UISupportsDocumentBrowser key, or by setting bother the UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace keys.
As explained in this documentation:
These keys enable other apps to open and edit the contents of your Documents directory in place. Your files also appear in both the Files app and the document browser. For more information, see the UIDocumentBrowserViewController class.

Access a .plist file in an iOS app through iTunes (or other ?)

I'm coding a small app to manage a guest list. To stock this list, I use a .plist file (It is an array -> .plist is practical.) I wanted to have the possibility of editing this file with my computer (I have to fill it with 1000 people or more...) Have some one a solution to make a file accessible with a Mac (With iTunes I suppose) ? (as Stop Motion : You can take the videos you have made in iTunes).
Thanks !
According to apple doc:
File-Sharing Support File-sharing support lets apps make user data files available in iTunes 9.1 and later. An app that declares its
support for file sharing makes the contents of its /Documents
directory available to the user. The user can then move files in and
out of this directory as needed from iTunes. This feature does not
allow your app to share files with other apps on the same device; that
behavior requires the pasteboard or a document interaction controller
object.
To enable file sharing for your app, do the following:
Add the UIFileSharingEnabled key to your app’s Info.plist file, and set the value of the key to YES. (The actual key name is
"Application supports iTunes file sharing")
Put whatever files you want to share in your app’s Documents directory.
When the device is plugged into the user’s computer, iTunes displays a File Sharing section in the Apps tab of the selected
device.
The user can add files to this directory or move files to the desktop.
Apps that support file sharing should be able to recognize when files
have been added to the Documents directory and respond appropriately.
For example, your app might make the contents of any new files
available from its interface. You should never present the user with
the list of files in this directory and ask them to decide what to do
with those files.
For additional information about the UIFileSharingEnabled key, see
Information Property List Key Reference.

How to view document directory in iOS emulator?

I wrote a React Native application that downloads a file and saves it to the document directory.
The application gives me a path like this:
/Users/laurent/Library/Developer/CoreSimulator/Devices/SOMEID/data/Containers/Data/Application/SOMEID/Documents
and using macOS Finder I can see that the file has indeed been created.
My problem is how to view this file from the iOS emulator? If I click on the Files app for instance, I can't see that file. Basically is this file available to the user from somewhere and, if so, where? Or maybe I need to save it to a different directory?
Your iOS app is sandboxed by default, meaning that no other app can access its resources. The simulator is very different since it runs on your mac and stores your files there so you can easily access them.
That said, it is very simple to expose your Documents folder by adding the appropriate keys to your app's info.plist:
Add the UISupportsDocumentBrowser key to grants access to all the documents in the app’s Documents directory and have them appear in the Files app (iOS 11 and above). When this is enabled, other apps can also have access to your documents when using UIDocumentBrowserViewController.
Add the UIFileSharingEnabled key to expose the app’s Documents directory to the desktop iTunes app. When combined with the LSSupportsOpeningDocumentsInPlace key, it will also enable Files app support and document browser as mentioned above.
By default any files your application downloads are only available from within that app, they will not show up in the file system of the device.
As far as I know there is no react-native library which allows you to access the iOS file system, so you will need to make use of native iOS code to solve your problem. Besides pointing you to the official documentation, there is not much more I can do to help.

iOS: Support App Group folders in local file provider

I understand that if I provide the UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace keys in Info.plist for my iOS app, files in my app's Documents folder are shown in Files.app ("On This iPad") and the documents browser.
Now my question - aside from writing a File Provider extension - is there any way to add an app group's folder or replace the Documents folder with a folder in the app group's folder?
For sharing between my extensions, I save everything in the App Group folder instead of Documents, but then, of course, Files.app doesn't have access to those files, that's why I'm asking.
I tried creating symbolic links from the documents folder to the actual file, and they are shown, but don't work correctly ("file doesn't exist").
I've also created a File Provider extension, but it was rejected by Apple because my extension isn't cloud-backed and was only for local files. According to my reviewer, a File Provider extension must be cloud-storage backed.
Thank you for your help and insights,
-Matt
It's pretty simple: No. :(
We are struggling with the same issue and its simple: You can't participate in the files app (or iTunes File Sharing) if you don't store your files in the Documents folder.
It seems like this is not well thought out. You should not integrate as a file provider unless you are actually providing a file system such as dropbox, at least that's what we've been told at WWDC. On the other side you should support stuff like iMessage extensions, today extensions,... which only are possible if your files are accessible through an app group. But this then automatically breaks the use of the Files.app as well as iTunes Filesharing.
We filed radars for that, any duplicate would help, I guess.

Resources