-
Enhance collaboration experiences with Messages
Discover how you can help improve communication and collaboration in your app with Collaboration in Messages. Learn how to tie a document to Messages conversations for simple sharing and discussion. Explore how you can keep everyone in the conversation up to date on the latest activity in the document. And find out how you can add customizable UI in your app to manage collaboration details and connect documents to Messages conversations and FaceTime calls.
To learn more about the SharedWithYou framework, we recommend watching "Add Shared with You to your app.” For more information on adding collaboration APIs to apps that have custom collaboration infrastructure, check out "Integrate your custom collaboration app with Messages.”Recursos
Vídeos relacionados
WWDC22
- Add Shared with You to your app
- Integrate your custom collaboration app with Messages
- Meet Transferable
- What's new in AppKit
- What's new in SwiftUI
WWDC21
-
Buscar neste vídeo...
-
-
4:08 - Create a CloudKit collaboration item provider
// CloudKit collaboration object // Starting collaboration let itemProvider = NSItemProvider() itemProvider.registerCKShare(container: container, allowedSharingOptions: CKAllowedSharingOptions.standard, preparationHandler: { // Create your share and save to server, or throw error return savedShare }) // Inviting to existing collaboration let itemProvider = NSItemProvider() itemProvider.registerCKShare(share, container: container, allowedSharingOptions: CKAllowedSharingOptions.standard) -
7:35 - Set up Share Sheet on iOS and Mac Catalyst
// Setting up Share Sheet - iOS and Mac Catalyst let activityViewController = UIActivityViewController(activityItems: [collaborationObject], applicationActivities: nil) presentingViewController.present(activityViewController, animated: true) -
7:47 - Set up Share Popover on macOS
// Setting up Share Popover - macOS let sharingServicePicker = NSSharingServicePicker(items: [collaborationObject]) sharingServicePicker.show(relativeTo: view.bounds, of: view, preferredEdge: .minY) -
8:22 - Provide metadata for CloudKit collaboration in Share Sheet (iOS, Mac Catalyst)
// Providing CloudKit metadata - iOS let configuration = UIActivityItemsConfiguration(itemProviders: [collaborationItemProvider]) configuration.perItemMetadataProvider = { (_, key) in switch key { case .linkPresentationMetadata: // Create LPLinkMetadata with title and imageProvider return metadata default: return nil } } let activityViewController = UIActivityViewController(activityItemsConfiguration: configuration) -
9:03 - Provide metadata for CloudKit collaboration in Share Popover (macOS)
// Providing CloudKit metadata - macOS let title = “Shared Item” let image = NSImage(contentsOfFile: “Shared_Item_Preview_Image.png”) let icon = NSImage(contentsOfFile: “App_Icon.png”) // Shared item source let previewRepresentingItem = NSPreviewRepresentingActivityItem(item: collaborationItemProvider, title: title, image: image, icon: icon) let picker = NSSharingServicePicker(items: [previewRepresentingItem]) -
10:21 - Create Transferable object for CloudKit collaboration with ShareLink
// SwiftUI CloudKit Transferable struct Note: Transferable { // Properties of the note e.g. name, preview image, content, ID, … var share: CKShare? func saveCKShareToServer() async throws -> CKShare { … } static var transferRepresentation: some TransferRepresentation { CKShareTransferRepresentation { note in if let share = note.share { return .existing(share, container: container, options: options) } else { return .prepareShare(container: container, options: options) { return try await note.saveCKShareToServer() } } } } } -
11:34 - Adopt ShareLink in SwiftUI
// SwiftUI ShareLink adoption struct ContentView: View { @State let item = ShareItem() var body: some View { ShareLink(item: item, preview: SharePreview(item.title, image: item.previewImage)) } } -
14:58 - Initialize the collaborationView
// Collaboration View let collaborationView = SWCollaborationView(itemProvider: itemProvider) collaborationView.activeParticipantCount = myModel.activePeople.count collaborationView.contentView = MyView(model: myModel) collaborationView.manageButtonTitle = "Custom Manage Button" -
18:11 - Observe when CKShare is saved with CKSystemSharingUIObserver
// Observing CKShare Changes let observer = CKSystemSharingUIObserver(container: container) observer.systemSharingUIDidSaveShareBlock = { _, result in switch result { case .success(let share): // Handle successfully starting share case .failure(let error): // Handle error } } -
18:47 - Observe when CKShare is removed with CKSystemSharingUIObserver
// Observing CKShare Changes observer.systemSharingUIDidStopSharingBlock = { _, result in switch result { case .success(let share): // Handle successfully starting share case .failure(let error): // Handle error } } -
20:44 - Posting notice for edit SWHighlightChangeEvent
// Post an SWHighlightChangeEvent Notice let highlightCenter: SWHighlightCenter = self.highlightCenter let highlight = try highlightCenter.collaborationHighlight(forURL: ckShareURL, error: &error) let editEvent = SWHighlightChangeEvent(highlight: highlight, trigger: .edit) highlightCenter.postNotice(for: editEvent) -
21:30 - Post an SWHighlightMentionEvent Notice
// Post an SWHighlightMentionEvent Notice let highlightCenter: SWHighlightCenter = self.highlightCenter let highlight = try highlightCenter.collaborationHighlight(forURL: ckShareURL, error: &error) let mentionEvent = SWHighlightMentionEvent(highlight: highlight, mentionedPersonCloudKitShareHandle: ckShareParticipantHandle) highlightCenter.postNotice(for: mentionEvent) -
21:58 - Post an SWHighlightPersistenceEvent Notice
// Post an SWHighlightPersistenceEvent Notice let highlightCenter: SWHighlightCenter = self.highlightCenter let highlight = try highlightCenter.collaborationHighlight(forURL: ckShareURL, error: &error) let renamedEvent = SWHighlightPersistenceEvent(highlight: highlight, trigger: .renamed) highlightCenter.postNotice(for: renamedEvent) -
22:11 - Post an SWHighlightMembershipEvent Notice
// Post an SWHighlightMembershipEvent Notice let highlightCenter: SWHighlightCenter = self.highlightCenter let highlight = try highlightCenter.collaborationHighlight(forURL: ckShareURL, error: &error) let membershipEvent = SWHighlightMembershipEvent(highlight: highlight, trigger: .addedCollaborator) highlightCenter.postNotice(for: membershipEvent)
-