Importing files in iOS : UIDocumentPicker vs UIDocumentBrowser - ios

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.

Related

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.

Opening Custom UTI in App not working in iOS13

I have been using AirDrop for ages now to allow a document to be passed from/to iPhone users from within my App. The App generates a straightforward CSV file which is then AirDropped (or could be emailed too) to another machine, where my App can open it and import it (the UTI is registered for the csv file type). This has been working fine for a long time, but I now see that devices running iOS13 no longer list my App as being able to import the file. If I run the same code on iOS12.4 (or earlier) it works fine, but on iOS13.1 my App is no longer registered to receive the data. The device can AirDrop to another device perfectly, and provided the destination is not iOS13 the import works fine. Whenever the destination is iOS13 my App simply is not listed as being available to receive. I can't see what might have changed.
The info settings (that work perfectly up until iOS13) are:
I cannot see anything in the iOS release notes that would suggest this has changed at all. Can anybody help with this?
Since you and your app didn't invent the CSV file type, you should use a standard UTI for CSV and not invent your own.
This means you should use the Imported UTIs section to declare the CSV UTI. The Export UTIs section should only be used by new UTIs that are unique to your app.
Here is my Imported UTI for CSV:
Here is my Document Type for CSV:
I have no trouble sending CSV files to my app under iOS 13 with these in place.
Also keep in mind that under iOS 13, you may need to tap on the "More" icon at the end of the list in the share sheet to see your app (and possibly others) as a choice.

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

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 :)

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 App's file associations ("open with..") / CFBundleDocumentTypes question

I have recently bought a perfect file manager app for my iPad. Everything in this app is great, besides that it cannot handle some specific file types.
So for example if I try to download the file in mobile safari and try to save it into the file manager (for further upload to dropbox, email and so on), I cannot do this because the app is not listed in the "open In" list.
The question is, how to associate this app with this specific file types? I've searched google and found out that app's file association information is stored in Info.plist file in the CFBundleDocumentTypes section.
So I just modified Info.plist but id didn't help. I also found the cracked version of this app and placed info.plist into the IPA file, reinstalled the app on the iPad and it also didn't help.
Any suggestions how to solve the problem?
You cannot just add the file types. The app also has to be coded to accept the request to open the file.
Try contacting the developer and ask for them to add this feature.
The problem is probably not the APP but a limitation on IOS: it is a random selection and only shows 10. I don't know if it randomly selects based on the ones you use most or what. You cannot change this other than to delete apps you don't use as often. But having said this, the app must also support the extension of the document you are trying to send: not just as a document it stores, but as a document it accepts as a transfer from another app. You can try to convert it first into a PDF and then open, if that's possible. Hope this helps.

Resources