@onekeyfe/react-native-cloud-kit-module 1.1.18 → 1.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CloudKitModule.podspec +1 -0
- package/ios/CloudKitModule.swift +11 -1
- package/package.json +1 -1
package/CloudKitModule.podspec
CHANGED
package/ios/CloudKitModule.swift
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import CloudKit
|
|
3
3
|
import NitroModules
|
|
4
|
+
import ReactNativeNativeLogger
|
|
4
5
|
|
|
5
6
|
class CloudKitModule: HybridCloudKitModuleSpec {
|
|
6
7
|
|
|
@@ -13,6 +14,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
13
14
|
public func isAvailable() throws -> Promise<Bool> {
|
|
14
15
|
return Promise.async {
|
|
15
16
|
let status = try await self.container.accountStatus()
|
|
17
|
+
OneKeyLog.info("CloudKit", "Account status: \(status.rawValue), available: \(status == .available)")
|
|
16
18
|
return status == .available
|
|
17
19
|
}
|
|
18
20
|
}
|
|
@@ -28,6 +30,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
28
30
|
let userRecordID = try await self.container.userRecordID()
|
|
29
31
|
userId = userRecordID.recordName
|
|
30
32
|
} catch {
|
|
33
|
+
OneKeyLog.warn("CloudKit", "Failed to get user record ID: \(error.localizedDescription)")
|
|
31
34
|
userId = nil
|
|
32
35
|
}
|
|
33
36
|
}
|
|
@@ -51,6 +54,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
51
54
|
|
|
52
55
|
public func saveRecord(params: SaveRecordParams) throws -> Promise<SaveRecordResult> {
|
|
53
56
|
return Promise.async {
|
|
57
|
+
OneKeyLog.info("CloudKit", "Saving record: \(params.recordID), type: \(params.recordType)")
|
|
54
58
|
let ckRecordID = CKRecord.ID(recordName: params.recordID)
|
|
55
59
|
let recordToSave: CKRecord
|
|
56
60
|
do {
|
|
@@ -65,6 +69,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
65
69
|
recordToSave[CloudKitConstants.recordDataField] = params.data as CKRecordValue
|
|
66
70
|
recordToSave[CloudKitConstants.recordMetaField] = params.meta as CKRecordValue
|
|
67
71
|
let savedRecord = try await self.database.save(recordToSave)
|
|
72
|
+
OneKeyLog.info("CloudKit", "Record saved: \(savedRecord.recordID.recordName)")
|
|
68
73
|
let createdAt = Int64((savedRecord.creationDate?.timeIntervalSince1970 ?? 0) * 1000)
|
|
69
74
|
let result = SaveRecordResult(
|
|
70
75
|
recordID: savedRecord.recordID.recordName,
|
|
@@ -82,6 +87,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
82
87
|
|
|
83
88
|
do {
|
|
84
89
|
let record = try await self.database.record(for: ckRecordID)
|
|
90
|
+
OneKeyLog.debug("CloudKit", "Record fetched: \(params.recordID)")
|
|
85
91
|
|
|
86
92
|
let data = record[CloudKitConstants.recordDataField] as? String ?? ""
|
|
87
93
|
let meta = record[CloudKitConstants.recordMetaField] as? String ?? ""
|
|
@@ -97,6 +103,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
97
103
|
modifiedAt: Double(modifiedAt)
|
|
98
104
|
))
|
|
99
105
|
} catch let error as CKError where error.code == .unknownItem {
|
|
106
|
+
OneKeyLog.debug("CloudKit", "Record not found: \(params.recordID)")
|
|
100
107
|
return Variant_NullType_RecordResult.first(NullType.null)
|
|
101
108
|
}
|
|
102
109
|
}
|
|
@@ -110,9 +117,10 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
110
117
|
|
|
111
118
|
do {
|
|
112
119
|
_ = try await self.database.deleteRecord(withID: ckRecordID)
|
|
120
|
+
OneKeyLog.info("CloudKit", "Record deleted: \(params.recordID)")
|
|
113
121
|
return Void()
|
|
114
122
|
} catch let error as CKError where error.code == .unknownItem {
|
|
115
|
-
|
|
123
|
+
OneKeyLog.debug("CloudKit", "Record not found for delete (OK): \(params.recordID)")
|
|
116
124
|
return Void()
|
|
117
125
|
}
|
|
118
126
|
}
|
|
@@ -172,9 +180,11 @@ class CloudKitModule: HybridCloudKitModuleSpec {
|
|
|
172
180
|
case .success:
|
|
173
181
|
// Sort by modification time descending to return latest first
|
|
174
182
|
let sorted = results.sorted { $0.modifiedAt > $1.modifiedAt }
|
|
183
|
+
OneKeyLog.info("CloudKit", "Query returned \(sorted.count) records for type: \(params.recordType)")
|
|
175
184
|
let queryResult = QueryRecordsResult(records: sorted)
|
|
176
185
|
continuation.resume(returning: queryResult)
|
|
177
186
|
case .failure(let error):
|
|
187
|
+
OneKeyLog.error("CloudKit", "Query failed for type \(params.recordType): \(error.localizedDescription)")
|
|
178
188
|
continuation.resume(throwing: error)
|
|
179
189
|
}
|
|
180
190
|
}
|