Related Session : Building Document Based app WWDC 2014
What is document based app
NSFileManager
only list the local doc, not for doc on iCloud or doc in other apps
NSMetadataQuery
combines all available including local ,remote and external doc from other apps. This populate the notification to inform hosting app for getting remote doc and any updates to the doc.
Thumbnails are generated automatically for some types of documents.
Recent List contains the document of user just worked on. Storing NSURL
is not robust as the doc may be moved. Use security scoped bookmarks as a pointer to the doc
NSFileCoordination
for read/write lock
NSFilePresenter
to receive the updates whenever the document has been modified from other parties.
Use background queue to create new doc as coordinated operations can block
Strongly suggested to use UIDocument
to read and write, invoke loadFromContents()
in background thread and completion on main queue
in iOS 9
NSProgressReporting
on UIDocument
protocol is used for telling how much work done.Content and thumbnails are done on background threads.
if providing custom thumbnails, make sure to thread-safety classes to create the images. UIViews
are not thread-safe. Use Core graphic suggested.
in iOS 8, the doc from other apps are copies. Presenting multiple copies to user is confusing.
in iOS 9, the doc may be directly reference to the another app documents as known as Open in place via UIDocumentMenuViewController
and UIDocument
Support Open in place :
LSSupportsOpeningDocumentsInPlace
key in info.plistfunc application(app: UIApplication, openUrl url: NSURL, options: [String: AnyObject]) -> Bool {
guard let shouldOpenInPlace = options[UIApplicationOpenURLOptionsOpenInPlaceKey] as? Bool else {
return false
}
//use the external url
let newURL = shouldOpenInPlace ? url : copyFileToContain(url)
documentBrowser.openDocumentAtURL(newURL)
return true
}