CKSubscription of type CKSubscriptionOptionsFiresOnRecordUpdate doesn't work
Its a known bug that update notifications are not working.
[CKFetchNotificationChangesOperation sometimes does not return UPDATE, DELETE notifications
[CloudKit push notifications on record update stopped working
[https://forums.developer.apple.com/thread/7288][3]
Alternatives to UPDATE notification that does not work
I have used a similar strategy. There are some drawbacks:
- more data (storage and transfer) usage
- limited subscription possibilities or you have to duplicate even more data.
- extra code in your app that you actually don't want to be there.
The only good solution to this problem is:
- Apple should fix it...
CloudKit: delete CKSubscription is not working
Ok, this isn't the definitive answer, but need to put some code down and the comments are too short. What does it all mean; the first method fetches any outstanding notifications, the second makes sure you the same page as regarding their attention.
You need to make sure you got something like place before deleting the subscriptions ideally.
Disclaimer this is demo code; and I haven't tested it extensively. But it should work.
func fetchSubsInPlace() {
let container = CKContainer(identifier: "iCloud.ch")
let publicDB = container.publicCloudDatabase
publicDB.fetchAllSubscriptionsWithCompletionHandler({subscriptions, error in
for subscriptionObject in subscriptions! {
let subscription: CKSubscription = subscriptionObject as CKSubscription
print("subscription \(subscription)")
}
})
}
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: NSError?) -> 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 = NSOperationQueue()
operationQueue.addOperation(markOperation)
}
let operationQueue = NSOperationQueue()
operationQueue.addOperation(operation)
}
}
Related Topics
Firebase Cloud Messaging Cannot Parse Topic Name
Apple Doesn't Recognize Imgur's Https
Google Signin: Unable to Disconnect iOS App
Change Cell Height by The Content of The Textview Inside The Cell
How to Figure Out When a HTML5 Video Player Enters The Full Screen Mode on iOS/Ipads
"Googleplus/Googleplus.H File Not Found" When Trying to Build My Project
Nsmanagedobject Setter Giving Me [ Myobject Setname:]: Unrecognized Selector Sent to Instance
Media Query Not Working for iPhone and Ipad
Tabbarcontroller Adding Custom Button Not Clickable Issue
How to Make One Side of a Div Pointy with CSS
Indexpathforrowatpoint Returns Nil Only for First Cell in a UItableview
How to Set Gradient Background Transparency on iOS Safari
Checking Cellular Network Type in iOS
How to Add Pagination in UItableview.
Data Repeat in UItableview When Scrolling
Detect Collision of Two UIview's in Swift
Value of Type 'string' Has No Member 'stringbytrimmingcharactersinset'