forked from pointfreeco/sqlite-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloudKitDemoApp.swift
More file actions
68 lines (61 loc) · 1.62 KB
/
CloudKitDemoApp.swift
File metadata and controls
68 lines (61 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import CloudKit
import SQLiteData
import SwiftUI
@main
struct CloudKitDemoApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
@Dependency(\.context) var context
init() {
if context == .live {
try! prepareDependencies {
try $0.bootstrapDatabase()
}
}
}
var body: some Scene {
WindowGroup {
if context == .live {
NavigationStack {
CountersListView()
}
}
}
}
}
class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let configuration = UISceneConfiguration(
name: "Default Configuration",
sessionRole: connectingSceneSession.role
)
configuration.delegateClass = SceneDelegate.self
return configuration
}
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
@Dependency(\.defaultSyncEngine) var syncEngine
var window: UIWindow?
func windowScene(
_ windowScene: UIWindowScene,
userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata
) {
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)
}
}
}