我正在尝试为包含用户的 CKReference 字段的记录设置 CKSubscription。但是无论何时创建记录,它都会忽略复合谓词的这一部分,并且通知永远不会出现。在 CKSubscription 的谓词中使用 CKReference 有什么不同吗?我进入仪表板以在我自己的用户记录 ID 下输入新记录(在模拟器中运行另一个用户时),因为我相信我读到如果记录来自设备,它将不会收到通知。非常感谢任何见解,因为我已经坚持了一个星期,并且无法在网上找到任何特定于此的内容。我能够获得真正的类型谓词通知,所以我认为我的基本设置没问题。
在仪表板中,我看到两个测试用户都有一个通用订阅,但没有看到任一用户的任何特定记录 ID(这有关系吗?):
Notifications.read (equals string)
Notifications.user (equals reference)
Run Code Online (Sandbox Code Playgroud)
当我执行 fetchAllSubscriptionsWithCompletionHandler 方法时,它会在调试器中将此设备的当前用户的特定记录 ID 显示为 CKReference。所以我不知道为什么它不起作用。
这是我首先创建 CKReference 然后将其用于谓词的代码:
var recordIDString = CKRecordID(recordName: "_a86dac8ee05f8c6ab35746bf9663d7b8")
// I normally store this string in the NSUserDefaults.
let userRef = CKReference(recordID: recordIDString, action: .DeleteSelf)
let predicate = NSPredicate(format: "user = %@", userRef)
let predicateTwo = NSPredicate(format: "read = %@", "")
// I want the read field to be empty, which tells me user has not read …Run Code Online (Sandbox Code Playgroud) 错误是:字段“__recordID”的值类型为引用,无法使用过滤器值类型字符串进行查询。
代码:
func getImage() {
let predicate = NSPredicate(format: "recordID = %@", myRecordID)
let query = CKQuery(recordType: "Images", predicate: predicate)
publicDB.performQuery(query, inZoneWithID: nil , completionHandler: ({ results, error in
if(error != nil) {
print("Error")
}
else {
if results!.count > 0 {
for record in results! {
print("I have results from query")
}
else {
print("query returned with no results")
}
}
}))
Run Code Online (Sandbox Code Playgroud)
myRecordID 是: 3F1CF4EC-95F4-4659-AA47-B00048B3BBAE 这是有效的
所以我通读了苹果给我们的例子(CloudKit 目录),我注意到每次你想写或读的时候,你都需要把你的 API 令牌放入脚本中。
现在 Javascript 是基于客户端的,这意味着每个用户都可以读取 API 令牌并可以读取和写入我的容器?!
此代码将位于其中一个 Javascript 文件中
CloudKit.configure({
locale: 'en-us',
containers: [{
// Change this to a container identifier you own.
containerIdentifier: 'com.example.apple-samplecode.cloudkit-catalog',
apiTokenAuth: {
// And generate a web token through CloudKit Dashboard.
apiToken: '<insert your token here>',
persist: true, // Sets a cookie.
signInButton: {
id: 'apple-sign-in-button',
theme: 'black' // Other options: 'white', 'white-with-outline'.
},
signOutButton: {
id: 'apple-sign-out-button',
theme: 'black'
}
},
environment: 'development'
}]
});
Run Code Online (Sandbox Code Playgroud)
现在的问题是:我是否遗漏了什么,或者是用户通过 Node 进行服务器到服务器通信的解决方案?
我正在尝试让 iCloud 在 iPhone 和 Apple Watch 之间工作(在 watchOS 3 上使用 CloudKit)。我已将 Watch Extension 中的云容器指定为与 iOS 目标中的云容器相同,但是在运行该应用程序时,我从我所做的查询中收到此错误:
Failure retrieving: Optional(<CKError 0x17d45cf0: "Unknown Item" (11/2003); server message = "did not find record type recordTypeId="Recommendation""; uuid = 37D53C78-FF19-4CE3-80BD-C1990F0135A2; container ID = "iCloud.mathsrobot.MathsRobot-LearnMaths.watchkitapp.watchkitextension">)
Run Code Online (Sandbox Code Playgroud)
从容器 ID,我可以看出它没有使用 iOS 应用程序容器,应该是iCloud.mathsrobot.MathsRobot-LearnMaths. 如何让它为 iOS 应用程序使用 iCloud 容器?
iOS 目标能力截图 iCloud 的主要 iOS 目标能力
观看目标功能截图 使用 iCloud 观看扩展目标功能
请在下面查看我更新的问题:
我正在使用 CloudKit 开发我的第一个应用程序。在查找交易之前,我正在尝试测试用户是否已连接到 iCloud。
这是我的代码(显示各种测试):
func isICloudContainerAvailable()->Bool {
CKContainer.default().accountStatus { (accountStat, error) in
if (accountStat == .available) {
print("iCloud is available")
}
else {
print("iCloud is not available")
}
}
CKContainer.default().accountStatus { (accountStatus, error) in
switch accountStatus {
case .available:
print("iCloud Available")
case .noAccount:
print("No iCloud account")
case .restricted:
print("iCloud restricted")
case .couldNotDetermine:
print("Unable to determine iCloud status")
}
}
if FileManager.default.ubiquityIdentityToken != nil {
//print("User logged in")
return true
}
else {
//print("User is not logged in")
return …Run Code Online (Sandbox Code Playgroud) 我在 CloudKit 中保存了图像作为资产。每个记录还有其他属性。我可以收集记录并使用其他属性,但我无法在我的 ImageView 中使用资产。我是 Swift 编程的新手,因此我收到的错误没有任何意义。
let container = CKContainer.default()
let publicDB = container.publicCloudDatabase
let query1 = CKQuery(recordType: "movieArray", predicate: predicate2)
publicDB.perform(query1, inZoneWith: nil) {(results:[CKRecord]?, error:Error?) in
if error != nil {
DispatchQueue.main.async {
print("Cloud Query Error - Fetch Establishments: \(String(describing: error))")
}
return
}
for record in results! {
DispatchQueue.main.async {
let asset = record["myImageKey"] as? CKAsset
let data = NSData(contentsOf: (asset?.fileURL)!)
let image = UIImage(data: data! as Data)
print("Test")
self.detailImage.image = image
}
self.movieCast.text = record.object(forKey: "Actors") …Run Code Online (Sandbox Code Playgroud) 我正在使用 CloudKit 并且正在检查是否已经创建了特定区域。
对于这个例子,假设一个区域没有设置,所以 CloudKit 检索我一个CKError.
这CKError有一个名为partialErrorsByItemIDwhich 类型的属性[AnyHashable : Error]?
这是代码:
fileprivate func checkIfZonesWereCreated() {
let privateDB = CKContainer.default().privateCloudDatabase
let op = CKFetchRecordZonesOperation(recordZoneIDs: [zoneID1, zoneID2])
op.fetchRecordZonesCompletionBlock = { (dict, err) in
if let err = err as? CKError, let _err = err.partialErrorsByItemID {
print(_err)
/* prints
[AnyHashable(<CKRecordZoneID: 0x60800003cba0; ownerName=__defaultOwner__, zoneName=TestZone>): <CKError 0x60400005a760: "Zone Not Found" (26/2036); server message = "Zone 'TestZone' does not exist"; uuid = ...-2DF4E13F81E2; container ID = "iCloud.com.someContainer">]
*/
// …Run Code Online (Sandbox Code Playgroud) Xcode 抛出一个非常模棱两可的错误:
'firesOnRecordCreation' 的含糊使用
在进行 CKQuerySubscription 时。实际上,它在添加到该调用的每个选项上都这样做。那是编译器错误吗?解决方案?
let predicate = NSPredicate(value: true)
let subscriptionID = "notes-changed"
let noteSubscription = CKQuerySubscription(recordType: "Notes",
predicate: predicate,
subscriptionID: subscriptionID,
options: [.firesOnRecordCreation,
.firesOnRecordDeletion,
.firesOnRecordUpdate])
Run Code Online (Sandbox Code Playgroud) 我有一个可运行的原生 iPhone/iPad 应用程序,我现在正尝试将其用作 Mac Catalyst 应用程序。一切似乎都在工作,除了当我在 iOS 版本上输入某些内容时,它“破坏”了 macOS 版本——我正在使用 CloudKit 和 CloudKit 订阅来监听数据库中的变化。
我把这个记录到日志中 3 次:
2020-04-25 09:58:35.612887+0300 MyApp[2871:206093] [assertion] Error acquiring assertion: <NSError: 0x600000d4cb40; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
2020-04-25 09:58:35.613919+0300 MyApp[2871:206093] [assertion] Error acquiring assertion: <NSError: 0x600000d4d290; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
2020-04-25 09:58:35.615102+0300 MyApp[2871:206093] [assertion] Error acquiring assertion: <NSError: 0x600000d4de00; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
Run Code Online (Sandbox Code Playgroud)
这种行为真的很奇怪。macOS 版本实际上并没有崩溃,但主窗口消失了,我必须在 XCode …
我有一个带有约束的数据模型,以确保属性是唯一的。
当我重新安装应用程序(数据在云中可用)时,同步失败并显示以下错误:
2020-07-16 10:33:13.401904+0200 Structured[40519:1639423] [error] error: CoreData+CloudKit: -[PFCloudKitImporterZoneChangedWorkItem applyAccumulatedChanges:error:]_block_invoke_2(440): Failed to save applied changes from import: Error Domain=NSCocoaErrorDomain Code=133021 "(null)" UserInfo={NSExceptionOmitCallstacks=true, conflictList=(
"NSConstraintConflict (0x600000ab0600) for constraint (\n day,\n month,\n year\n): database: 0xba46bc9a935a60ef <x-coredata://8AB04C93-B9EB-413F-BD0C-9EF854D89D20/Day/p1>, conflictedObjects: (\n \"0xba46bc9a934e60ef <x-coredata://8AB04C93-B9EB-413F-BD0C-9EF854D89D20/Day/p4>\"\n)"
)}
Run Code Online (Sandbox Code Playgroud)
此错误再次出现几次,并且远程数据永远不会与本地可用数据同步和合并。
我以通常的方式初始化持久性容器:
lazy var persistentContainer: NSPersistentCloudKitContainer = {
let container = NSPersistentCloudKitContainer(name: "Today")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
return container
}() …Run Code Online (Sandbox Code Playgroud)