App not launching from document in iCloud Drive - ios

My app works fine with iCloud, at least in terms of the metadataQuery locating documents in my app's container. I can open and save those documents and see them in iCloud Drive both in iOS 10.x and 11 (through the Files app).
But, when viewing them in iCloud Drive, tapping them does not launch my app, but rather displays a view that identifies the document (accurately) as a MyApp document. If I tap a Pages document, though, Pages is launched and the document opened.
What am I missing? Have I not set a preference properly?
Further, in iOS 11, if I Share->Add People, my document sends properly to the other iOS 11 device and the message that's sent uses my icon and identifies it as a MyApp document. But tapping that sharing message (in Messages) asks to open the document in Files rather than in MyApp, and does not place the file in the MyApp container, but one level higher where metadataQuery doesn't find it. The same sequence with a Pages document opens Pages and puts the doc into the Pages container. Again, Files is accurately showing my document's icon and identifying it as a MyApp document, but seemingly not connecting that to my app.
Does the explanation make sense? Any idea what I've not done right or am not understanding? Thanks for any insights!

Found the secret. The plist needs a property that allows it to receive a request to open the document. That property is LSSupportsOpeningDocumentsInPlace and it's a Boolean that defaults to NO but should be set to YES for the appropriate AppDelegate functions to be called. When I added that (I found it in the sample app ShapeEdit), tapping my app's doc in iCloud Drive launched the app and called the function with my code to open the doc.

Related

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.

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 detect changes in the application documents directory in iOS app?

I am currently working on an app with the file sharing feature.
We have a view to ask the user to plug his device to iTunes to add files if there is no files in the app.
I would like to remove this view when the iOS app is launched on the device and when the user add at least one file with iTunes to the app.
Is there a way to do that with the default FileManager ? Like a delegate or something to detect events from the document directory of the app ?
I have looked on the web and found some pods but only for macOS.
I have also tried something with a Timer which will get the files from the document directory of the app each 0.25 seconds, but I don't think this is the best way to do what I want.
Thanks for your help.
EDIT:
Thanks to the MartinR's comment below, the following link helps me to do what I wanted
Notification if user modifies contents of documents directory via iTunes File sharing

How do I properly enable iCloud document sync for iOS app?

In my cordova iOS app, users can back up their data to a file which is saved in the Documents folder within the app's container, which then should be synced to iCloud. However, though the file is saved it is never synced to iCloud, so clearly I must be missing something. These are the steps I have taken:
iCloud container registered on developer.apple.com and iCloud Documents capability enabled in xcode:
NSUbiquitousContainers dictionary added to Info.plist:
Archive build created and uploaded to App Store, build released to testers via Test Flight (Note: app has already gone through review process and been released to App Store).
Note, Cordova config.xml does not contain BackupWebStorage setting so cloud backup should be enabled (not sure exactly whether this affects document sync).
User saves backup file, which is saved to app's Documents folder (Note: the app uses the cordova-plugin-file plugin to save the file to the location denoted by the plugin variable cordova.file.documentsDirectory):
At this point I would have expected to see xBrowserSync appear in Storage & iCloud usage settings, but I do not:
And neither do I see an xBrowserSync folder appear in the iCloud Drive app:
And of course I never see the files synced to my Mac or on icloud.com.
Clearly I'm missing something but I can't see what. I've read many SO posts regarding getting this working and I find Apple's documentation unclear and confusing so I'm kind of stuck at this point. Could someone please point me in the right direction?
After some further reading I believe I know what's missing here. I hadn't realised you need to explicitly tell iOS to upload a file to iCloud Document Storage, which is what will allow files to appear in iCloud Drive on the user's devices.
So, I need to write some (iOS) code that utilise the FileManager class to:
Call the url(forUbiquityContainerIdentifier:) method in order to get the location of the local iCloud container and initialise it (at which point the app will appear in Storage & iCloud usage settings)
Tell iOS to upload the file to iCloud by calling setUbiquitous(_:itemAt:destinationURL:)
I'm building a very basic Cordova plugin to do this. I'll update this answer with a link when I'm finished.
Edit:
The cordova plugin I developed is called cordova-plugin-icloud-document-storage. It currently only implements uploading documents to iCloud (i.e. setUbiquitous), it doesn't implement the other iCloud functionality of the FileManager class (such as managing cloud updates or version conflicts). If anyone would like to develop this functionality please do submit a pull request.

Switching between apps with URL Schemes (iOS)

I'm developing an iPhone app with Swift which acts on certain file types (.xml &.zip). I've added these filetypes to the project file as a UTI (Uniform Type Identifiers). When accessing these sorts of files, usually from my email, I press and hold the file and a menu pops up from below. I choose my app icon that says "Open in MyApp". Is there a way that I can return to the email which triggered this event from within the app?
I've done some research on this and found that URL Schemes are the best way for inter - app communication, but you cannot arbitrarily open an app just to open it.
https://developer.apple.com/library/mac/documentation/Miscellaneous/Reference/UTIRef/Introduction/Introduction.html
The vision I have in mind is sort of how Google apps communicate with each other. For example, when opening a link from gmail, it switches apps to chrome. When chrome loads, the page back navigator is in Chrome displays the text similar to "back to gmail"
In iOS 9 the system implements this automatically, as seen in this screenshot here.

Resources