云工具包看不到已保存的订阅

时间:2019-09-10 04:22:08

标签: icloud cloudkit ckquerysubscription

我在云工具包公共数据库默认区域中创建了一个空记录,作为与某些字段的“联系”。然后,我保存订阅,它就成功创建了。 然后我运行获取所有订阅并打印它们。

private let contactSubscriptionID = "All Contact Creations and Deletions"
private func iCloudSubscribeToChanges(){

    if self.subscriptionIsLocallyCached {
        return
    }

    let predicate = NSPredicate(format: "TRUEPREDICATE")

    let subscriptionContact = CKQuerySubscription(
        recordType: contact,
        predicate: predicate,
        subscriptionID: self.contactSubscriptionID,
        options: [
            .firesOnRecordCreation,
            .firesOnRecordUpdate,
            .firesOnRecordDeletion
        ])

    let notificationInfo = CKNotificationInfo()
    notificationInfo.shouldSendContentAvailable = true
    notificationInfo.alertBody = ""

    subscriptionContact.notificationInfo = notificationInfo


    self.publicDB?.save(subscriptionContact, completionHandler: { (subscription, error) in
        //handle error
        guard error == nil else {
            if let ckerror = error as? CKError {
                self.aErrorHandler.handleCkError(ckerror: ckerror)

            }
            return
        }
        print("Successfully added Contact creation and deletion subscription.")
        self.checkSubscriptions()

    })

}

func checkSubscriptions() {
    let op = CKFetchSubscriptionsOperation.fetchAllSubscriptionsOperation()
    op.fetchSubscriptionCompletionBlock = { (subscriptions, error) in

       print("subscriptions: \(subscriptions)")
    }
    defaultContainer.publicCloudDatabase.add(op)


}

输出显示为: 成功添加联系人创建和删除订阅。 订阅:可选([:])

(1)是否有一种方法可以在仪表板上的公共数据库上成功创建订阅? (2)为什么未正确保存已保存的订阅? 有人可以告诉我吗?

0 个答案:

没有答案