-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
AppDelegate.swift
55 lines (40 loc) · 1.98 KB
/
AppDelegate.swift
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
//
// AppDelegate.swift
// IceCream
//
// Created by 蔡越 on 10/17/2017.
// Copyright (c) 2017 Nanjing University. All rights reserved.
//
import UIKit
import IceCream
import CloudKit
import RealmSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var syncEngine: SyncEngine?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
syncEngine = SyncEngine(objects: [
SyncObject(type: Dog.self),
SyncObject(type: Cat.self),
SyncObject(type: Person.self, uListElementType: Cat.self)
])
/// If you wanna test public Database, comment the above syncEngine code and uncomment the following one
/// Besides, uncomment Line 26 to 28 in Person.swift file
// syncEngine = SyncEngine(objects: [SyncObject<Person>()], databaseScope: .public)
application.registerForRemoteNotifications()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = TabBarViewController()
window?.makeKeyAndVisible()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let dict = userInfo as? [String: NSObject], let notification = CKNotification(fromRemoteNotificationDictionary: dict), let subscriptionID = notification.subscriptionID, IceCreamSubscription.allIDs.contains(subscriptionID) {
NotificationCenter.default.post(name: Notifications.cloudKitDataDidChangeRemotely.name, object: nil, userInfo: userInfo)
completionHandler(.newData)
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
// How about fetching changes here?
}
}