Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Examples/CloudKitDemo/CloudKitDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ struct CloudKitDemoApp: App {
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@Dependency(\.defaultSyncEngine) var syncEngine
var window: UIWindow?

func windowScene(
_ windowScene: UIWindowScene,
userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata
Expand All @@ -62,5 +63,19 @@ struct CloudKitDemoApp: App {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
}

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let cloudKitShareMetadata = connectionOptions.cloudKitShareMetadata
else {
return
}
Task {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
}
}
#endif
21 changes: 19 additions & 2 deletions Examples/CloudKitPlayground/CloudKitPlaygroundApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ struct CloudKitPlaygroundApp: App {
$0.defaultDatabase = try! appDatabase()
$0.defaultSyncEngine = try! SyncEngine(
for: $0.defaultDatabase,
tables: ModelA.self, ModelB.self, ModelC.self
tables: ModelA.self,
ModelB.self,
ModelC.self
)
}
}
Expand Down Expand Up @@ -48,12 +50,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
@Dependency(\.defaultSyncEngine) var syncEngine
var window: UIWindow?

func windowScene(
_ windowScene: UIWindowScene,
userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata
) {
@Dependency(\.defaultSyncEngine) var syncEngine
Task {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
}

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let cloudKitShareMetadata = connectionOptions.cloudKitShareMetadata
else {
return
}
Task {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
Expand Down
17 changes: 16 additions & 1 deletion Examples/Reminders/RemindersApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
@Dependency(\.defaultSyncEngine) var syncEngine
var window: UIWindow?

func windowScene(
_ windowScene: UIWindowScene,
userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata
) {
@Dependency(\.defaultSyncEngine) var syncEngine
Task {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
}

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let cloudKitShareMetadata = connectionOptions.cloudKitShareMetadata
else {
return
}
Task {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ configure how they want to share the record. A record can be _unshared_ by prese
## Accepting shared records

Extra steps must be taken to allow a user to _accept_ a shared record. Once the user taps on the
share link sent to them (whether that is by text, email, etc.), the app will be launched and a
special `userDidAcceptCloudKitShareWith` delegate method will be invoked in the app's scene
delegate. Your app must implement this delegate method and invoke the
``SyncEngine/acceptShare(metadata:)`` method.
share link sent to them (whether that is by text, email, etc.), the app will be launched with
special options provided or a special delegate method will be invoked in the app's scene delegate.
You must implement these delegate methods and invoke the ``SyncEngine/acceptShare(metadata:)``
method.

As a simplified example, a `UIWindowSceneDelegate` subclass can implement the delegate method like
so:
Expand All @@ -75,6 +75,7 @@ so:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
@Dependency(\.defaultSyncEngine) var syncEngine
var window: UIWindow?

func windowScene(
_ windowScene: UIWindowScene,
userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata
Expand All @@ -83,6 +84,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
}

func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let cloudKitShareMetadata = connectionOptions.cloudKitShareMetadata
else {
return
}
Task {
try await syncEngine.acceptShare(metadata: cloudKitShareMetadata)
}
}
}
```

Expand Down
Loading