cloud documents in your application€¦ · building a modern document-based application session...

207
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Cloud Documents in Your Application Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks Johannes Fortmann Software Engineer

Upload: others

Post on 01-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Cloud Documents in Your ApplicationBuilding a modern document-based application

Session 234 Mike Hess Software Engineer

Frameworks

!

Johannes Fortmann Software Engineer

Page 2: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Changes to iCloud

Page 3: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Changes to iCloud

iCloud daemon rewritten on top of CloudKit

Page 4: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Changes to iCloud

iCloud daemon rewritten on top of CloudKit

Windows support

Page 5: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Changes to iCloud

iCloud daemon rewritten on top of CloudKit

Windows support

iCloud folder in Finder

Page 6: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Changes to iCloud

iCloud daemon rewritten on top of CloudKit

Windows support

iCloud folder in Finder

Access to iCloud folder on iOS

Page 7: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Agenda

Page 8: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Agenda

Document access

Page 9: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Agenda

Document access

Document discovery

Page 10: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Agenda

Document access

Document discovery

Displaying thumbnails in your UI

Page 11: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Agenda

Document access

Document discovery

Displaying thumbnails in your UI

Accessing documents outside your iCloud container

Page 12: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Agenda

Document access

Document discovery

Displaying thumbnails in your UI

Accessing documents outside your iCloud container

Providing document storage to other apps

Page 13: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Documents in iCloudWhat is a document anyway?

Page 14: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Documents in iCloudWhat is a document anyway?

A standalone entity, understood as such by the user

Page 15: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Documents in iCloudWhat is a document anyway?

A standalone entity, understood as such by the user

User might want to exchange (e.g., move it, modify it, send it via email)

Page 16: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Documents in iCloudWhat is a document anyway?

A standalone entity, understood as such by the user

User might want to exchange (e.g., move it, modify it, send it via email)

Page 17: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Documents in iCloudWhat is a document anyway?

A standalone entity, understood as such by the user

User might want to exchange (e.g., move it, modify it, send it via email)

Page 18: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Documents in iCloudWhat is a document anyway?

A standalone entity, understood as such by the user

User might want to exchange (e.g., move it, modify it, send it via email)

Page 19: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Dealing with Documents

Page 20: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Page 21: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Important—use file coordination!

Page 22: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Important—use file coordination!

Why? Avoid data loss!

Page 23: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Important—use file coordination!

Why? Avoid data loss!

There may be multiple readers/writers on the same document

Page 24: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Important—use file coordination!

Why? Avoid data loss!

There may be multiple readers/writers on the same document• Examples—iCloud, background saving, etc.

Page 25: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Page 26: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

With file coordination

!Doc

Page 27: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

With file coordination

!Doc

Page 28: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Page 29: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Without file coordination

!Doc

Page 30: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesReading and writing documents

Without file coordination

Data Loss!

Page 31: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesUIDocument makes things simple!

Page 32: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesUIDocument makes things simple!

UIDocument/NSDocument do all heavy lifting for you

Page 33: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesUIDocument makes things simple!

UIDocument/NSDocument do all heavy lifting for you• File coordination

Page 34: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesUIDocument makes things simple!

UIDocument/NSDocument do all heavy lifting for you• File coordination

• Background queues

Page 35: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesUIDocument makes things simple!

UIDocument/NSDocument do all heavy lifting for you• File coordination

• Background queues

• Multiple high-level APIs for every purpose

Page 36: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesExample—reading a document from disk

Highest level—we read the file, you get an NSData or NSFileWrapper object - loadFromContents:ofType:error:

Page 37: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesExample—reading a document from disk

Highest level—we read the file, you get an NSData or NSFileWrapper object - loadFromContents:ofType:error:

!

Intermediate level—we coordinate, you get an NSURL - readFromURL:error:

Page 38: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Access—Best PracticesExample—reading a document from disk

Highest level—we read the file, you get an NSData or NSFileWrapper object - loadFromContents:ofType:error:

!

Intermediate level—we coordinate, you get an NSURL - readFromURL:error: !

Lowest level—provided for hooking - openWithCompletionHandler:

Page 39: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Page 40: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

Page 41: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access

Page 42: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access- coordinateAccessWithIntents:queue:byAccessor:

Page 43: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access - coordinateAccessWithIntents:queue:byAccessor:

Use NSFileAccessIntent to specify purpose of coordination

Page 44: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access - coordinateAccessWithIntents:queue:byAccessor:

Use NSFileAccessIntent to specify purpose of coordinationsrcInt = [NSFileAccessIntent readingIntentWithURL:srcURL options:srcOpts]; dstInt = [NSFileAccessIntent writingIntentWithURL:dstURL options:dstOpts]; [fileCoordinator coordinateAccessWithIntents:@[src, dst] queue:queue byAccessor:^(NSError *error) { // Do operation here with [srcInt URL] and [dstInt URL] }];

Page 45: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access - coordinateAccessWithIntents:queue:byAccessor:

Use NSFileAccessIntent to specify purpose of coordinationsrcInt = [NSFileAccessIntent readingIntentWithURL:srcURL options:srcOpts]; dstInt = [NSFileAccessIntent writingIntentWithURL:dstURL options:dstOpts]; [fileCoordinator coordinateAccessWithIntents:@[src, dst] queue:queue byAccessor:^(NSError *error) { // Do operation here with [srcInt URL] and [dstInt URL] }];

Page 46: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access - coordinateAccessWithIntents:queue:byAccessor:

Use NSFileAccessIntent to specify purpose of coordinationsrcInt = [NSFileAccessIntent readingIntentWithURL:srcURL options:srcOpts]; dstInt = [NSFileAccessIntent writingIntentWithURL:dstURL options:dstOpts]; [fileCoordinator coordinateAccessWithIntents:@[src, dst] queue:queue byAccessor:^(NSError *error) { // Do operation here with [srcInt URL] and [dstInt URL] }];

Page 47: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Asynchronous File CoordinationNew File Coordination APIs

Existing File Coordination APIs were synchronous

New File Coordinator API for asynchronous file coordination access - coordinateAccessWithIntents:queue:byAccessor:

Use NSFileAccessIntent to specify purpose of coordinationsrcInt = [NSFileAccessIntent readingIntentWithURL:srcURL options:srcOpts]; dstInt = [NSFileAccessIntent writingIntentWithURL:dstURL options:dstOpts]; [fileCoordinator coordinateAccessWithIntents:@[src, dst] queue:queue byAccessor:^(NSError *error) { // Do operation here with [srcInt URL] and [dstInt URL] }];

Page 48: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Discovering and Listing Documents

Page 49: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

Page 50: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs

Page 51: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs

Previously slow to pick up local changes (deletes, creates, renames)

Page 52: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs

Previously slow to pick up local changes (deletes, creates, renames)

Page 53: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs

Previously slow to pick up local changes (deletes, creates, renames)

!Doc 3Long delay…

Page 54: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs

Previously slow to pick up local changes (deletes, creates, renames)

!Doc 3

NSMetadataItem 3

Page 55: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

Page 56: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs easier to use directly with “stitching”

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

Page 57: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs easier to use directly with “stitching”

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

!Doc 3File coordination hook

updates query quickly

Page 58: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs easier to use directly with “stitching”

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

!Doc 3

NSMetadataItem 3

Page 59: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryDiscovering new and existing documents

NSMetadataQuery APIs easier to use directly with “stitching”

No file coordination required when listing documents

Your App

Your App’s Container

!Doc 1

!Doc 2

NSMetadataItem 1

NSMetadataItem 2

!Doc 3

NSMetadataItem 3

Page 60: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryAccessing metadata on documents

NSMetadataQuery can list non-local documents

New APIs to access metadata on those documents - getPromisedItemResourceValue:forKey:error:

Page 61: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryAccessing metadata on documents

NSMetadataQuery can list non-local documents

New APIs to access metadata on those documents - getPromisedItemResourceValue:forKey:error: - promisedItemResourceValuesForKeys:error:

Page 62: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document DiscoveryAccessing metadata on documents

NSMetadataQuery can list non-local documents

New APIs to access metadata on those documents - getPromisedItemResourceValue:forKey:error: - promisedItemResourceValuesForKeys:error:

!

New file coordinator flags for dealing with metadata NSFileCoordinatorReadingImmediatelyAvailableMetadataOnly NSFileCoordinatorWritingContentIndependentMetadataOnly

Page 63: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Thumbnails

Page 64: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Thumbnails

Best user experience when listing documents is to show previews

Page 65: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Thumbnails

Best user experience when listing documents is to show previews

Possible previously but required custom implementation

Page 66: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ThumbnailsDisplaying thumbnails in your UI

Page 67: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ThumbnailsDisplaying thumbnails in your UI

New thumbnail keys available! • NSURLThumbnailDictionaryKey – NSDictionary

- NSThumbnail1024x1024SizeKey – UIImage / NSImage

• NSURLThumbnailKey (OSX) – NSImage

Page 68: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ThumbnailsDisplaying thumbnails in your UI

New thumbnail keys available! • NSURLThumbnailDictionaryKey – NSDictionary

- NSThumbnail1024x1024SizeKey – UIImage / NSImage

• NSURLThumbnailKey (OSX) – NSImage

Easiest way to get thumbnails to display in UI - getPromisedItemResourceValue:forKey:error: - promisedItemResourceValuesForKeys:error:

Page 69: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ThumbnailsSaving thumbnails

Easiest way to save thumbnails is through UIDocument - fileAttributesToWriteToURL:forSaveOperation:error:

Page 70: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ThumbnailsSaving thumbnails

Easiest way to save thumbnails is through UIDocument - fileAttributesToWriteToURL:forSaveOperation:error:

Or you can set thumbnails manually - setResourceValue:forKey:error:

Page 71: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ThumbnailsSaving thumbnails

Easiest way to save thumbnails is through UIDocument - fileAttributesToWriteToURL:forSaveOperation:error:

Or you can set thumbnails manually - setResourceValue:forKey:error:

OS X generates thumbnails automatically using your Quick Look plug-in

Page 72: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Discover DocumentsOutside Your Container

Page 73: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 74: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

No easy way to discover documents outside your app from within your app

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 75: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

No easy way to discover documents outside your app from within your app

Your App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 76: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

No easy way to discover documents outside your app from within your app

Your App Other App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 77: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

No easy way to discover documents outside your app from within your app

Your App Other App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 78: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

No easy way to discover documents outside your app from within your app

Your App Other App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

!Doc 3

Page 79: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Not Always EasyDifficult to access documents from another app

No easy way to discover documents outside your app from within your app

Your App Other App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

!Doc 3

Page 80: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccessing documents directly

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 81: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccessing documents directly

Better user experience to open documents directly

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 82: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccessing documents directly

Better user experience to open documents directly

Your App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 83: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccessing documents directly

Better user experience to open documents directly

Your App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 84: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccess documents outside your container

Page 85: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccess documents outside your container

UIDocumentPickerViewController allows your users to • Discover documents outside of your app’s sandbox

• Grant your app permissions to access and edit the discovered documents

Page 86: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccess documents outside your container

UIDocumentPickerViewController allows your users to • Discover documents outside of your app’s sandbox

• Grant your app permissions to access and edit the discovered documents

Must opt-in to have documents displayed

NSUbiquitousContainerIsDocumentScopePublic = YES

Page 87: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Discovery Made EasierAccess documents outside your container

UIDocumentPickerViewController allows your users to • Discover documents outside of your app’s sandbox

• Grant your app permissions to access and edit the discovered documents

Must opt-in to have documents displayed

NSUbiquitousContainerIsDocumentScopePublic = YES

Great new UI which you display in your app

Page 88: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

DemoUsing the document picker in a simple application

Page 89: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Page 90: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Easy to display UIDocumentPickerViewController

Page 91: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Easy to display UIDocumentPickerViewController

Users can now select documents from other apps’ containers

Page 92: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Easy to display UIDocumentPickerViewController

Users can now select documents from other apps’ containers

Easy to make your container show up in UIDocumentPickerViewController

Page 93: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing External DocumentsDocument references, scoped access, and bookmarks

Johannes Fortmann Software Engineer

Page 94: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesDocument references in your container

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 95: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesDocument references in your container

Your app always has access to its own container

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 96: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesDocument references in your container

Your app always has access to its own container

Your App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 97: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesDocument references in your container

Your app always has access to its own container

For other documents, we save a document reference

Your App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

Page 98: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesDocument references in your container

Your app always has access to its own container

For other documents, we save a document reference

Your App

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 4

!Doc 3

!Doc 3

Page 99: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope

NSMetadataItem 1

NSMetadataItem 2Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 4

Page 100: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope

NSMetadataItem 1

NSMetadataItem 2Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

Page 101: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

NSMetadataUbiquitousItemURLInLocalContainerKey

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

NSMetadataItem 1

NSMetadataItem 2

NSMetadataItem 3

Page 102: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

NSMetadataUbiquitousItemURLInLocalContainerKey

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

NSMetadataItemURLKey

NSMetadataItem 1

NSMetadataItem 2

NSMetadataItem 3

Page 103: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

NSMetadataUbiquitousItemURLInLocalContainerKey

NSMetadataItem 1

NSMetadataItem 2

NSMetadataItem 3

NSMetadataItemURLKey

Page 104: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

NSMetadataUbiquitousItemIsExternalDocumentKey

NSMetadataItem 1

NSMetadataItem 2

NSMetadataItem 3

Page 105: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

NSMetadataUbiquitousItemIsExternalDocumentKey

NO

NO

YES

NSMetadataItem 1

NSMetadataItem 2

NSMetadataItem 3

Page 106: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesNew attributes

NSMetadataQueryUbiquitousDocumentsScope NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

Your App’s Container

!Doc 1

Other App’s Container

!Doc 2

!Doc 3

!Doc 3

!Doc 4

NSMetadataUbiquitousItemContainerDisplayNameKey

MyApp

MyApp

OtherApp

NSMetadataItem 1

NSMetadataItem 2

NSMetadataItem 3

Page 107: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesWhy do you need the document reference?

Page 108: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesWhy do you need the document reference?

The document picker is running out-of-process for security

Page 109: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesWhy do you need the document reference?

The document picker is running out-of-process for security

The only way to get a document outside your container is by using the picker

URL returned by the picker is security scoped

URL

Scope

Serialized NSURL

URL

Page 110: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesWhy do you need the document reference?

The document picker is running out-of-process for security

The only way to get a document outside your container is by using the picker

URL returned by the picker is security scoped

When saving a URL (state restoration, recents list), scope would be lost

URL

Scope

Serialized NSURL

URL

Page 111: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesWhy do you need the document reference?

The document picker is running out-of-process for security

The only way to get a document outside your container is by using the picker

URL returned by the picker is security scoped

When saving a URL (state restoration, recents list), scope would be lost

You need a way to get back to the scoped URL

URL

Scope

Serialized NSURL

URL

Page 112: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesWhy do you need the document reference?

The document picker is running out-of-process for security

The only way to get a document outside your container is by using the picker

URL returned by the picker is security scoped

When saving a URL (state restoration, recents list), scope would be lost

You need a way to get back to the scoped URL

Document references come with scope pre-attached

URL

Scope

Serialized NSURL

URL

Page 113: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Page 114: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Sometimes enumerating documents is not the right choice

Page 115: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Sometimes enumerating documents is not the right choice• E.g., you want to restore a previously opened document immediately

Page 116: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Sometimes enumerating documents is not the right choice• E.g., you want to restore a previously opened document immediately

Creating a bookmark encodes a portable reference to a document

Page 117: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Sometimes enumerating documents is not the right choice• E.g., you want to restore a previously opened document immediately

Creating a bookmark encodes a portable reference to a document

Includes the security scope

Page 118: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Bookmark creation via API -bookmarkDataWithOptions:

Page 119: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Bookmark creation via API -bookmarkDataWithOptions:

URL

Scope

NSData +

Scope

Page 120: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Bookmark creation via API -bookmarkDataWithOptions: !

+URLByResolvingBookmarkData:savedBookmarkData

URL

Scope

NSData +

Scope

Page 121: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Managing Document ReferencesBookmarks for state restoration

Bookmark creation via API -bookmarkDataWithOptions: !

+URLByResolvingBookmarkData:savedBookmarkData

URL

Scope

NSData +

Scope

URL

Scope

Page 122: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document References and the PickerUIDocumentPickerMode—Import vs. Open

Page 123: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Other App’s Container

Document References and the PickerUIDocumentPickerMode—Import vs. Open

Open mode will create a bookmark and a security-scoped URL

Your App’s Container

!Doc 1

!Doc 2

!Doc 3

!Doc 3

Page 124: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Other App’s Container

Document References and the PickerUIDocumentPickerMode—Import vs. Open

Open mode will create a bookmark and a security-scoped URL

Import mode will not create a bookmark

Your App’s Container

!Doc 1

!Doc 2

!Doc 3

Page 125: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Other App’s ContainerTemporary Location

Document References and the PickerUIDocumentPickerMode—Import vs. Open

Open mode will create a bookmark and a security-scoped URL

Import mode will not create a bookmark

You can read the file, but it is temporary

Your App’s Container

!Doc 1

!Doc 2

!Doc 3

!Doc 3

Page 126: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Other App’s ContainerTemporary Location

Document References and the PickerUIDocumentPickerMode—Import vs. Open

Open mode will create a bookmark and a security-scoped URL

Import mode will not create a bookmark

You can read the file, but it is temporary

Make a copy soon if you want to hang on to it

Your App’s Container

!Doc 1

!Doc 2

!Doc 3

Page 127: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

How to Create a New DocumentNo write access except in your sandbox

Page 128: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

How to Create a New DocumentNo write access except in your sandbox

You will not have general access to other app’s containers

Page 129: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

How to Create a New DocumentNo write access except in your sandbox

You will not have general access to other app’s containers

Write in your own container locally or in a temporary location

Page 130: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

How to Create a New DocumentNo write access except in your sandbox

You will not have general access to other app’s containers

Write in your own container locally or in a temporary location

Afterwards, you can move the document

Page 131: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

Page 132: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

Page 133: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

The file will be moved to the location the user picks

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

Page 134: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

The file will be moved to the location the user picks

You will get a URL and a reference for the new location

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 3

Page 135: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

The file will be moved to the location the user picks

You will get a URL and a reference for the new location

The URL behaves like the one returned by Open

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 3

Page 136: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

The file will be moved to the location the user picks

You will get a URL and a reference for the new location

The URL behaves like the one returned by Open

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

Page 137: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

The file will be moved to the location the user picks

You will get a URL and a reference for the new location

The URL behaves like the one returned by Open

Export mode if you don’t want to hang on to the reference

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

Page 138: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Existing DocumentsMoving a document

Use UIDocumentPicker -initWithURL: and your existing document

The file will be moved to the location the user picks

You will get a URL and a reference for the new location

The URL behaves like the one returned by Open

Export mode if you don’t want to hang on to the reference

Your App’s Container

!Doc 1

!Doc 2

Other App’s Container

!Doc 3

!Doc 3

Page 139: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ManagementSummary

Page 140: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ManagementSummary

Document references for enumerating picked documents

Page 141: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ManagementSummary

Document references for enumerating picked documents

Bookmarks for state restoration

Page 142: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ManagementSummary

Document references for enumerating picked documents

Bookmarks for state restoration

Modes for Import, Open, Export, Move

Page 143: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document ManagementSummary

Document references for enumerating picked documents

Bookmarks for state restoration

Modes for Import, Open, Export, Move

Allows the user to access all their iCloud documents

Page 144: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsProviding document storage to other apps

Page 145: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Page 146: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Page 147: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Page 148: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Page 149: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Can offer the same picker modes as the standard picker

Page 150: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Can offer the same picker modes as the standard picker

Implemented using two extensions

Page 151: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Can offer the same picker modes as the standard picker

Implemented using two extensions

Document Picker Extension

Page 152: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Can offer the same picker modes as the standard picker

Implemented using two extensions

UIDocumentPickerVC

Document Picker Extension

Page 153: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Can offer the same picker modes as the standard picker

Implemented using two extensions

UIDocumentPickerVC

Document Picker Extension

File Provider Extension

Page 154: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

What Is a Document Provider?Alternative storage locations

Alternative way for a third-party to provide document storage

Same perspective from the host app’s point of view

Selectable from the document picker

Can offer the same picker modes as the standard picker

Implemented using two extensions

UIDocumentPickerVC

Document Picker Extension

NSFileCoordinator

File Provider Extension

Page 155: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

User App

Your Extension

UIKit/Foundation

Host

API

Page 156: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

initWithDocumentTypes:inMode:

UIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 157: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

prepareForPresentationInMode:

Document Picker

UIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 158: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

dismissGrantingAccessToURL:

Document Picker

UIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 159: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

documentPicker:didPickDocumentAtURL:

Document Picker

UIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 160: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

coordinateReadingItemAtURL:

Document Picker

NSFileCoordinatorUIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 161: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

startProvidingItemAtURL:

File ProviderDocument Picker

NSFileCoordinatorUIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 162: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

completion()

File ProviderDocument Picker

NSFileCoordinatorUIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 163: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

accessorBlock()

File ProviderDocument Picker

NSFileCoordinatorUIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 164: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsData flow for selection and read access

dataWithContentsOfURL:

File ProviderDocument Picker

NSFileCoordinatorUIDocumentPickerVC

User App

Your Extension

UIKit/Foundation

Host

API

Page 165: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsSecurity and bookmarks

Page 166: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsSecurity and bookmarks

Document provider extensions don’t take part in document reference mechanism

Page 167: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsSecurity and bookmarks

Document provider extensions don’t take part in document reference mechanism

But bookmarks still work

Page 168: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsSecurity and bookmarks

Document provider extensions don’t take part in document reference mechanism

But bookmarks still work

File provider returns/resolves an identifier

Page 169: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsSecurity and bookmarks

Document provider extensions don’t take part in document reference mechanism

But bookmarks still work

File provider returns/resolves an identifier

Access is controlled by isolation layer

Page 170: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API

User App User App

Page 171: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API bookmarkDataWithOptions:

NSURL

User App User App

Page 172: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API persistentIdentifierForItemAtURL:

File Provider

NSURL

User App User App

Page 173: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API NSString *identifier

File Provider

NSURL

User App User App

Page 174: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API NSData *bookmarkData

File Provider

NSURL

User App User App

Page 175: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API URLByResolvingBookmarkData:

File Provider

NSURLNSURL

User App User App

Page 176: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API URLForItemWithPersistentIdentifier: providePlaceholderAtURL:

File ProviderFile Provider

NSURLNSURL

User App User App

Page 177: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API

File ProviderFile Provider

NSURLNSURL

User App User App

URLForItemWithPersistentIdentifier: providePlaceholderAtURL:

Page 178: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API NSURL *url

File ProviderFile Provider

NSURLNSURL

User App User App

Page 179: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API getPromisedItemResourceValue: NSFileCoordinator API

File ProviderFile Provider

NSURLNSURL

User App User App

Page 180: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsBookmark data flow

Non-UI Extension

UIKit/Foundation

Host

API

File ProviderFile Provider

NSURLNSURL

User App User App

getPromisedItemResourceValue: NSFileCoordinator API

Page 181: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsWriting files

Storage App’s Folder

!Doc 1User App

Page 182: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsWriting files

Host app uses file coordination to write file

Storage App’s Folder

!Doc 1User App

Page 183: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsWriting files

Host app uses file coordination to write file

Storage App’s Folder

!Doc 1User App

!Doc 1*

Page 184: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsWriting files

Host app uses file coordination to write file

Soon after, itemChangedAtURL: is called on the file provider

Storage App’s Folder

!Doc 1User App File Provider

!Doc 1*

Page 185: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Document Provider ExtensionsWriting files

Host app uses file coordination to write file

Soon after, itemChangedAtURL: is called on the file provider

File provider can e.g., initiate an upload

Storage App’s Folder

!Doc 1User App File Provider

!Doc 1*

Page 186: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

DemoBuilding a simple Document Provider

Page 187: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Page 188: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Xcode template to get you started with a Document Provider

Page 189: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Xcode template to get you started with a Document Provider

Document Provider shows up next to iCloud picker

Page 190: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Xcode template to get you started with a Document Provider

Document Provider shows up next to iCloud picker

Sample code is available to display each of the picker modes

Page 191: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor users

Page 192: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor users

On iOS 8, users can choose to continue using iCloud Documents or migrate to iCloud Drive

Page 193: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor users

On iOS 8, users can choose to continue using iCloud Documents or migrate to iCloud Drive

On OS X Yosemite, users can choose to migrate to iCloud Drive or changes will no longer update across devices

Page 194: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor users

On iOS 8, users can choose to continue using iCloud Documents or migrate to iCloud Drive

On OS X Yosemite, users can choose to migrate to iCloud Drive or changes will no longer update across devices

After an account is migrated to iCloud Drive, only devices using iCloud Drive will propagate changes to each other

Page 195: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor developers

Page 196: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor developers

The OS X Yosemite Developer Preview and the iOS 8 Beta use iCloud Drive

Page 197: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

From Documents in theCloud to iCloud DriveFor developers

The OS X Yosemite Developer Preview and the iOS 8 Beta use iCloud Drive

New features are only available in iCloud Drive

Page 198: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

Page 199: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

File coordination for document access

Page 200: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

File coordination for document access

Discovery and display of files

Page 201: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

File coordination for document access

Discovery and display of files

Using UIDocumentPicker to access files outside your container

Page 202: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Summary

File coordination for document access

Discovery and display of files

Using UIDocumentPicker to access files outside your container

Document Provider extensions to support third-party providers

Page 203: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

More Information

Dave DeLong App Frameworks Evangelist [email protected]

Jake Behrens App Frameworks Evangelist [email protected]

Page 204: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

More Information

Documentation iCloud for Developers http://developer.apple.com/icloud

Document Picker Programming Guide http://developer.apple.com

Apple Developer Forums http://devforums.apple.com

Page 205: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Related Sessions

• Introducing CloudKit Mission Tuesday 3:15PM

• Creating Extensions for iOS and OS X, Part 1 Mission Tuesday 2:00PM

• Creating Extensions for iOS and OS X, Part 2 Mission Wednesday 11:30AM

Page 206: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes

Labs

• Extensions Lab Frameworks Lab B Thursday 2:00PM

Page 207: Cloud Documents in Your Application€¦ · Building a modern document-based application Session 234 Mike Hess Software Engineer Frameworks! Johannes Fortmann Software Engineer. Changes