I'm trying to add iCloud Drive functionality to my iPhone app, by providing 2 features:
import a document which is stored on iCloud Drive to my local app
export a document from local store to iCloud Drive
The first part is done, and it was pretty easy. I used UIDocumentPicker with UIDocumentPickerModeImport to obtain a file url, which I just read to use the document in my app.
The second part, however, kind of confuses me. If I understand it correctly, all I have to do is instantiate a UIDocumentPicker with the file url of some document from the app local store, and the UIDocumentPicker will do all the rest (= saving to iCloud Drive, in case the user picks a location there).
Is this correct? Because this is what I've implemented. And while the files show up in the folder from picker selection, they will not sync neither to my Mac nor to www.icloud.com. So it seems like they are somehow stored in "the document picker on my phone", whatever this means.
Am I doing something wrong? The file I copied to the iCloud Drive folder on my mac perfectly showed up in the import-picker on the iPhone.
Actually, the files just turned up in finder (and also www.icloud.com). So it must have been some sync issue, or it just takes a while for it to sync.
Question answered/closed :)
Related
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.
In my App I would like to import various document types (video, audio, photo's, pdf and text). I can use UIImagePickerController for the photo's and videos. I can use UIDocumentPickerViewController to get all file types from an iCloud drive - but this does not seem to find any files I have created on this device (and not added to iCloud). I feel like I am missing something fundamental. NSOpenPanel is there for OSX, is there nothing equivalent for iOS?
UIDocumentPickerViewController can only access files in iCloud or a similar service (eg DropBox). There is no way to access files outside your app's sandbox. They must first be moved (or copied) to iCloud.
In my app creates a file on iCloud (outside of the Documents container). This works fine.
I wanted to test the presence/absence of that file. So I built up a NSMetadataQuery that actually detects the file when it is in the cloud. No problem.
Now, I deleted all my apps data from the cloud (using the System preferences), as well as all instances of my app.
Built from scratch and launched the app again. The query is still detecting the file, though it obviously doesn't exist any more, any where...
Any idea how I can get a "correct" file list?
If you want to know what the iCloud service thinks is correct, visit https://developer.icloud.com/ and browse around. That will show the server-side view of the iCloud account.
I would like to create a NSPersistentDocument in Mac OS X and read this document as a UIManagedDocument on iOS 7.
Is this possible?
Are both file formats compatible?
Thank you!
Interesting question - I can confirm that the basic core data files are compatible. I have a Mac app and an iOS app using the same file that gets synced using iCloud. The app is a document based app and currently I have been storing the actual database file in iCloud so the whole file gets sync'ed by iCloud.
This works fine but obviously if a user opens the file on two devices and is not careful about saving and closing there is a possibility their changes may be overridden.
Apple has approved the Mac app which uses standard NSPersistentDocument to create and save files. Unfortunately they have rejected the iOS apps with some obscure reference to not conforming to their data storage guidelines, saying that documents must be stored in /Documents directory if they need to be backed up to iCloud. Well if the user has selected iCloud then I store the files in the iCloud location provided by the API calls.
Anyway I am still waiting to hear back from them about what is specifically wrong with this approach since it seems to be the same one used by Pages and other document based apps.
If I try using UIManagedDocument then iOS creates a folder structure and stores the database inside this folder structure. The Mac app File->Open dialog then shows this folder structure as well as a file that essentially looks like a the normal sqlite file. But then perhaps OS X 10.8.4 does not implement the latest iCloud/Core Data stuff - who knows...
EDIT
Here is a link to code examples and videos showing OSX and iOS app integration using Core Data and iCloud. http://ossh.com.au/design-and-technology/software-development/uimanageddocument-icloud-integration/
I agree this is definitely possible. I'm using NSPersistent document on OS X 10.8/10.9/10.10 with a binary core data format (no wrappers - plain files). On iOS i'm using UIDocument. Core data works fine in both environments.
Apple says NSPersistentDocument does not support iCloud. It is more correct to say it isn't fully supported. Most of the NSDocument support (which includes iCloud Document Library access from 10.8) will work. Handling of conflicted files on open works.
You can't enable auto save (which is listed as a requirement for iCloud Documents in the iCloud Design Guide). Autosave works asynchronously and is definitely not supported by NSPersistentDocument.
So if you handle file saving, and conflicts, it is possible to use NSPersistent document. There are some quirks: so, for example, if an iCloud change arrives on OS X for a document that is open, the normal NSDocument response would be to automatically reopen the document. This doesn't happen - and there is no warning the file has changed until you are about to save the file. But at least there is a warning. On iOS it is easier to detect changes as they happen by using UIDocumentStateChangedNotification.
I have a simple survey iPad app. The data is saved in a TSV (tab separated file). I'm looking for an easy way to export this TSV file to a computer (without emailing it, if possible, and without doing it through iTunes).
App data on iOS is not directly accessible from a connected computer. It's not like you can mount the iPad's flash drive directly on a computer, navigate to the app's data directory, and copy the file to the computer. You have to have something with rights to access the data.
Some options are:
email or otherwise 'share' the data from within the iPad app.
Make the app's data accessible via iTunes
Turn the app into an FTP client or server
Dropbox integration (There was some problem where Apple was rejecting apps that did this, but i don't know the current state)
Have a look at IExplorer. It's a great little program / app that let's you access your iPad's file system from your computer. You can just drag and drop any file from your iPad to your computer.