iOS Files app won't open my app from another folder - ios

I have an issue while implementing file-based features on my iOS app. I need to open some files inside my app, which I do with an UIDocumentPickerViewController. Everything works great.
Except… when I try to open Files from the iOS 11's Files app. It works as expected when the file is in the "MyAppName" On My iPhone Folder, but if the file is in a random folder on iCloud, nothing. The Files app only tries to display a preview.
Both Application supports iTunes file sharing and Supports opening documents in place are set to YES on my Info.plist. When opening from the Documents folder from Files, AppDelegate's application(_ open inputURL) is called as expected.
Someone has an idea? Thanks!
I use iOS 11.4.1 on my device, and my code is all Swift.

Ok, I found the issue. For Files to open your app with your custom document type, you need to set LSHandlerRank to Owner. I hope it will help someone else :)

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

Importing files in iOS : UIDocumentPicker vs UIDocumentBrowser

As per the documentation, both UIDocumentPickerViewController and UIDocumentBrowserViewController can be used for importing documents outside an apps sandbox.
For selecting & importing a document from local document providers/cloud locations, which one for the above is best suited.Can i still use UIDocumentPickerViewController in iOS 11 ?
As per the following documentation Apple documentation for document picker , Before your app can use the document picker, you must turn on the iCloud Documents capabilities in Xcode and an iCloud container should be mapped to the appId.Is this mandatory if i'm only doing import operation ? I have tried using UIDocumentPickerViewController and it seems to be returning selected file path correctly even without the above mentioned entitlements.
You do not need the entitlement if you do not need your own iCloud container. If you just want to import files, you can use UIDocumentPickerViewController without adding an entitlement.
Yes, UIDocumentPickerViewController works on iOS 11.
The UIDocumentBrowserViewController has to be the rootview of your app, therefore from my experience you can't use within an existing APP and be part of a NavigationControl (you will not be able to get the back buttons properly). In these cases we need to use the UIDocumentPickerViewController. Hope this helps.

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.

How to search through iPhone filesystem downloads folder for mp3 files in react native

I'm working on an react native ios app where I want to look through the iPhone's downloads folder for .mp3 files that I can play. I've found a library react-native-fs but right now I am only able to see files added to my app and I can't figure out how to search for .mp3 files already on the iPhone. Any advice on libraries to use or code would be appreciated.
Code for my project: https://github.com/Laybium/laybium
In iOS apps have access only to their sandboxes. There's no such a thing as a Downloads folder, because there's no folder all apps may share.

Copy file to/from NSDocumentDirectory during dev

I'm playing with NSDocumentDirectory and saving files on my iPhone. I have created a dictionary and saved it successfully to NSDocumentDirectory and I can re-load it upon re-launch of my app. However, during development I would like to actually browse and copy files to and from NSDocumentDirectory. Is there a way via X-Code or Finder or iTunes to see the contents of my app's NSDocumentDirectory?
The real goal here to move a file generated on my iPhone to my iPad, but starting with copying back and forth from Mac to device would be great!
Any advice is much appreciated.
You can transfer files to / from app's Document directory through the File sharing feature in iTunes. To do so, you have to set UIFileSharingEnabled property to YES in your app-info.plist. See this question if you have problems setting it up.
Download iFunBox. It will allow you to access the IOS file system.
The latest version is here.
IPhoneExplorer is available for Mac and Windows.

Resources