gpt4 book ai didi

ios - 即使删除 CKSubscription 并读取它们后,CloudKit 也会发送多个推送通知

转载 作者:行者123 更新时间:2023-11-29 01:07:43 25 4
gpt4 key购买 nike

我将表的 CKSubscription 设置为“在创建记录时触发”。当我需要更新 CKSubscription 的特定实例时,我确保在添加它之前先将其删除。

但现在每当我保存新的 CKRecord 时,我都会收到四个相同的推送通知实例。有没有人经历过这个?如果是这样,是否有解决此问题的方法?

最佳答案

是的,您需要用这样的代码告诉它您处理了通知?

func fetchNotificationChanges() {
let operation = CKFetchNotificationChangesOperation(previousServerChangeToken: nil)

var notificationIDsToMarkRead = [CKNotificationID]()

operation.notificationChangedBlock = { (notification: CKNotification) -> Void in
// Process each notification received
if notification.notificationType == .query {
let queryNotification = notification as! CKQueryNotification
let reason = queryNotification.queryNotificationReason
let recordID = queryNotification.recordID

print("reason \(reason)")
print("recordID \(recordID)")
// Do your process here depending on the reason of the change

// Add the notification id to the array of processed notifications to mark them as read
notificationIDsToMarkRead.append(queryNotification.notificationID!)
}
}

operation.fetchNotificationChangesCompletionBlock = { (serverChangeToken: CKServerChangeToken?, operationError: Error?) -> Void in
guard operationError == nil else {
// Handle the error here
return
}

// Mark the notifications as read to avoid processing them again
let markOperation = CKMarkNotificationsReadOperation(notificationIDsToMarkRead: notificationIDsToMarkRead)
markOperation.markNotificationsReadCompletionBlock = { (notificationIDsMarkedRead: [CKNotificationID]?, operationError: NSError?) -> Void in
guard operationError == nil else {
// Handle the error here
return
}
}

let operationQueue = OperationQueue()
operationQueue.addOperation(markOperation)
}

let operationQueue = OperationQueue()
operationQueue.addOperation(operation)
}


}

关于ios - 即使删除 CKSubscription 并读取它们后,CloudKit 也会发送多个推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36146007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com