Skip to content

Commit

Permalink
去掉 iCloud 同步
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Jun 4, 2024
1 parent a49b998 commit 8ed3dcd
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 59 deletions.
25 changes: 25 additions & 0 deletions Bark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@
06CF783C21C7A50300A052D7 /* Sources */,
06CF783D21C7A50300A052D7 /* Frameworks */,
06CF783E21C7A50300A052D7 /* Resources */,
73BB82AB466F692F871A6876 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -896,6 +897,8 @@
"${PODS_CONFIGURATION_BUILD_DIR}/Material/com.cosmicmind.material.icons.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/Material/com.cosmicmind.material.fonts.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/MercariQRScanner/QRScannerAssets.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/Realm/realm_objc_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift/realm_swift_privacy.bundle",
"${PODS_ROOT}/SVProgressHUD/SVProgressHUD/SVProgressHUD.bundle",
);
name = "[CP] Copy Pods Resources";
Expand All @@ -905,13 +908,35 @@
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/com.cosmicmind.material.icons.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/com.cosmicmind.material.fonts.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/QRScannerAssets.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/realm_objc_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/realm_swift_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/SVProgressHUD.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Bark/Pods-Bark-resources.sh\"\n";
showEnvVarsInLog = 0;
};
73BB82AB466F692F871A6876 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-NotificationServiceExtension/Pods-NotificationServiceExtension-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/Realm/realm_objc_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/RealmSwift/realm_swift_privacy.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/realm_objc_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/realm_swift_privacy.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NotificationServiceExtension/Pods-NotificationServiceExtension-resources.sh\"\n";
showEnvVarsInLog = 0;
};
96E966B1F9EF139B935A8BB1 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
30 changes: 15 additions & 15 deletions Bark/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CloudKit
import CrashReporter
import IceCream
//import IceCream
import IQKeyboardManagerSwift
import Material
import UIKit
Expand All @@ -17,15 +17,15 @@ import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
var syncEngine: SyncEngine?
// var syncEngine: SyncEngine?
func setupRealm() {
// Tell Realm to use this new configuration object for the default Realm
Realm.Configuration.defaultConfiguration = kRealmDefaultConfiguration

// iCloud 同步
syncEngine = SyncEngine(objects: [
SyncObject(type: Message.self)
], databaseScope: .private)
// // iCloud 同步
// syncEngine = SyncEngine(objects: [
// SyncObject(type: Message.self)
// ], databaseScope: .private)

#if DEBUG
let realm = try? Realm()
Expand Down Expand Up @@ -148,15 +148,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
notificatonHandler(userInfo: response.notification.request.content.userInfo)
}

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 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)
// }
// }

private func notificatonHandler(userInfo: [AnyHashable: Any]) {
let navigationController = Client.shared.currentNavigationController
Expand Down
13 changes: 10 additions & 3 deletions Controller/MessageListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,17 @@ class MessageListViewModel: ViewModel, ViewModelType {
guard let messages = strongSelf.getResults(filterGroups: filterGroups.value, searchText: nil)?.filter("createDate >= %@", date) else {
return
}


// 不再使用icecream 了
// 所以需要手动删除
// try? realm.write {
// for msg in messages {
// msg.isDeleted = true
// }
// }
try? realm.write {
for msg in messages {
msg.isDeleted = true
}
realm.delete(messages)
}
}

Expand Down
7 changes: 4 additions & 3 deletions Controller/MessageSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ class MessageSettingsViewModel: ViewModel, ViewModelType {

let settings: [MessageSettingItem] = {
var settings = [MessageSettingItem]()
settings.append(.label(text: "iCloud"))
settings.append(.iCloudStatus)
settings.append(.label(text: NSLocalizedString("iCloudSync")))
// settings.append(.label(text: "iCloud"))
// settings.append(.iCloudStatus)
// settings.append(.label(text: NSLocalizedString("iCloudSync")))
settings.append(.label(text: NSLocalizedString("historyMessage")))
settings.append(.backup(viewModel: MutableTextCellViewModel(
title: "\(NSLocalizedString("export"))/\(NSLocalizedString("import"))",
text: Observable.merge([restoreSuccess, input.viewDidAppear])
Expand Down
6 changes: 3 additions & 3 deletions Model/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Fin. All rights reserved.
//

import IceCream
//import IceCream
import RealmSwift
import UIKit
class Message: Object {
Expand All @@ -29,5 +29,5 @@ class Message: Object {
}
}

extension Message: CKRecordConvertible {}
extension Message: CKRecordRecoverable {}
//extension Message: CKRecordConvertible {}
//extension Message: CKRecordRecoverable {}
33 changes: 13 additions & 20 deletions Model/Object+Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,23 @@ import RealmSwift

extension Object {
func toDictionary() -> [String: AnyObject] {
let properties = self.objectSchema.properties.map { $0.name }
var dicProps = [String: AnyObject]()
for (key, value) in self.dictionaryWithValues(forKeys: properties) {
if let value = value as? ListBase {
dicProps[key] = value.toArray1() as AnyObject
} else if let value = value as? Object {
dicProps[key] = value.toDictionary() as AnyObject
} else if let value = value as? Date {
dicProps[key] = Int64(value.timeIntervalSince1970) as AnyObject
self.objectSchema.properties.forEach { property in
if property.isArray {
var arr: [[String: AnyObject]] = []
for obj in self.dynamicList(property.name) {
arr.append(obj.toDictionary())
}
dicProps[property.name] = arr as AnyObject
} else if let value = self[property.name] as? Object {
dicProps[property.name] = value.toDictionary() as AnyObject
} else if let value = self[property.name] as? Date {
dicProps[property.name] = Int64(value.timeIntervalSince1970) as AnyObject
} else {
dicProps[key] = value as AnyObject
let value = self[property.name]
dicProps[property.name] = value as AnyObject
}
}
return dicProps
}
}

extension ListBase {
func toArray1() -> [AnyObject] {
var _toArray = [AnyObject]()
for i in 0 ..< self._rlmArray.count {
let obj = unsafeBitCast(self._rlmArray[i], to: Object.self)
_toArray.append(obj.toDictionary() as AnyObject)
}
return _toArray
}
}
6 changes: 4 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def pods
pod 'SwiftyJSON'
pod 'DeviceKit'
pod 'DefaultsKit', :git => 'https://github.com/nmdias/DefaultsKit'
pod 'IceCream'
# pod 'IceCream'
pod 'RealmSwift'
pod 'CryptoSwift'
pod 'IQKeyboardManagerSwift'

Expand Down Expand Up @@ -43,7 +44,8 @@ end


target 'NotificationServiceExtension' do
pod 'IceCream'
# pod 'IceCream'
pod 'RealmSwift'
pod 'Kingfisher'
pod 'CryptoSwift'
pod 'SwiftyJSON'
Expand Down
22 changes: 9 additions & 13 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ PODS:
- Differentiator (5.0.0)
- DropDown (2.3.13)
- FDFullscreenPopGesture (1.1)
- IceCream (2.0.4):
- RealmSwift (< 10.8.0)
- IQKeyboardManagerSwift (6.5.10)
- Kingfisher (6.3.1)
- KVOController (1.2.0)
Expand All @@ -29,11 +27,11 @@ PODS:
- RxSwift (~> 6.2)
- ObjectMapper (4.2.0)
- PLCrashReporter (1.11.1)
- Realm (10.7.7):
- Realm/Headers (= 10.7.7)
- Realm/Headers (10.7.7)
- RealmSwift (10.7.7):
- Realm (= 10.7.7)
- Realm (10.50.1):
- Realm/Headers (= 10.50.1)
- Realm/Headers (10.50.1)
- RealmSwift (10.50.1):
- Realm (= 10.50.1)
- RxCocoa (6.2.0):
- RxRelay (= 6.2.0)
- RxSwift (= 6.2.0)
Expand All @@ -57,7 +55,6 @@ DEPENDENCIES:
- DeviceKit
- DropDown
- FDFullscreenPopGesture
- IceCream
- IQKeyboardManagerSwift
- Kingfisher
- KVOController
Expand All @@ -68,6 +65,7 @@ DEPENDENCIES:
- "NSObject+Rx"
- ObjectMapper
- PLCrashReporter
- RealmSwift
- RxCocoa
- RxDataSources
- RxGesture
Expand All @@ -84,7 +82,6 @@ SPEC REPOS:
- Differentiator
- DropDown
- FDFullscreenPopGesture
- IceCream
- IQKeyboardManagerSwift
- Kingfisher
- KVOController
Expand Down Expand Up @@ -128,7 +125,6 @@ SPEC CHECKSUMS:
Differentiator: e8497ceab83c1b10ca233716d547b9af21b9344d
DropDown: 8a2116376c1981888557f72ec2ffc9a5e0e456ec
FDFullscreenPopGesture: a8a620179e3d9c40e8e00256dcee1c1a27c6d0f0
IceCream: 717d516a1c634eba8eaa8ce7d3d7bc5f7e40c2fa
IQKeyboardManagerSwift: 52962c76ab33532f15ad9f3ff4e5715eda5335bb
Kingfisher: 016c8b653a35add51dd34a3aba36b580041acc74
KVOController: d72ace34afea42468329623b3379ab3cd1d286b6
Expand All @@ -140,8 +136,8 @@ SPEC CHECKSUMS:
"NSObject+Rx": 61cf1f7306a73dcef8b36649198af0813ec18dfd
ObjectMapper: 1eb41f610210777375fa806bf161dc39fb832b81
PLCrashReporter: 5d2d3967afe0efad61b3048d617e2199a5d1b787
Realm: 8010af8b7a576ba501729bcbc54a3cd1f1f7dca3
RealmSwift: dc17e6d649c12a8996f9e962c3fe6cef356885c4
Realm: 36bc9fe2681d7cf234aa487e7990821c772206a2
RealmSwift: 84a370d3d4f191d327a9f8ade1f064a274f79847
RxCocoa: 4baf94bb35f2c0ab31bc0cb9f1900155f646ba42
RxDataSources: aa47cc1ed6c500fa0dfecac5c979b723542d79cf
RxGesture: f059f2aeef966fb17dad56ee440e76410f10e55f
Expand All @@ -151,6 +147,6 @@ SPEC CHECKSUMS:
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
SwiftyJSON: 2f33a42c6fbc52764d96f13368585094bfd8aa5e

PODFILE CHECKSUM: 73cfda85b7a345d896330d72bc61822356f98586
PODFILE CHECKSUM: c9560d9c6653dd0da638d1f49876c91a02632de6

COCOAPODS: 1.15.2

0 comments on commit 8ed3dcd

Please sign in to comment.