Is it possible to cause CloudKit to send a notification to a device at a specified time without doing anything but fire the notification?

Is it possible to cause CloudKit to send a notification to a device at a specified time without doing anything but fire the notification? I wonder if CloudKit can serve as a notification provider server to work with the Apple Push Notification service to fire a notification and run code in the app.

Accepted Reply

The problem is scheduling. CloudKit sits passively so nothing will cause it to wake up at, for example, 3:25pm next Tuesday, and send out a remote notification. You could create your own server and use that to trigger a remote notifcation.


That said, you could use a CKQuerySubscription with a query that was satisfied by any file that was modifed at a time after, for example, 3:25pm next Tuesday. And then you could run a background app that modifed a dummy file every minute. That would trigger a remote notification associated with the subscription.

Replies

I think I need to user a remote notification because I got information that said that a remote notification will wake the app up whereas a local notification requires user interaction to wake the app up. Am I correct on this?

The problem is scheduling. CloudKit sits passively so nothing will cause it to wake up at, for example, 3:25pm next Tuesday, and send out a remote notification. You could create your own server and use that to trigger a remote notifcation.


That said, you could use a CKQuerySubscription with a query that was satisfied by any file that was modifed at a time after, for example, 3:25pm next Tuesday. And then you could run a background app that modifed a dummy file every minute. That would trigger a remote notification associated with the subscription.

That doesn't sound like something Apple would like.

Hitting CloudKit with one new modified file every minute is not something that Apple would find problematic. I believe they have a 'delay response' trigger when the combined use by all of your deployed apps hits CloudKit more than 20 times in one second. This is 1000 times less.

It won't serve my needs. I am looking for a way to sound an alarm, as in alarm clock, at the exact time. That's what the notification is for.

"exact time" is undefined. To within a milisecond, second or minute?

This approach should work to within a minute.

Within a second.

You could explore an earlier trigger followed by precise timing code in the newly awoken app. You would need to do that since remote notifications are not precise to more than a few seconds.


To trigger at 3:02:00 trigger at 3:01:00 based on the every-minute wake up and then set a 60 second timer within the app. That presumes an app can stay awake in the background for 60 seconds. If an app cannot stay awake for 60 seconds, then working backwards: if an app can stay awake in the background for X seconds you would need to send out a possible remote notification every (X-5) seconds, cause an app on a particular device to sense the trigger that occurs anytime after (desired alarm time -X), cause that remote trigger to set a delay for (desired alarm time - now), and when that delay ended sound the alarm.

I have found from documentation that an app stays awake 3 minutes after it goes into the background, but I thought with remote notifications that the app doesn't have to be awake for the app to receive the notification. Am I wrong about this?

The app does not have to be 'awake' for the app to receive a remote notification and become awakened. If your 3 minutes is correct then you only need to ping CloudKit every 2.5 minutes. Set the CKSubscription to fire whenever a record is modified and the time of modification (e.g. 3:01 pm) is after 2.5 minutes before the next alarm (e.g. 3:03 pm - therefore schedule for anytime after 3:00:30 pm). Upon receiving a remote notifcation (at 3:01) check the precise alarm time and set the alarm.