Pranav Wadhwa
Pranav Wadhwa

Reputation: 7736

Fire push notification after delay using CloudKit

I am working on push notifications using CloudKit. Generally, I use the option .firesOnRecordCreation to identify when I want the push notification to send. E.g. -

let subscription = CKQuerySubscription(recordType: "SomeRecord", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil), options: .firesOnRecordCreation)

CKContainer.default().publicCloudDatabase.save(subscription) { (result, error) -> Void in
    //check for result and error
}

This is a CKQuerySubscriptionOptions. However, I want to send the push notifications a few days later. How can I achieve this? Thanks!

Upvotes: 1

Views: 234

Answers (1)

breakingobstacles
breakingobstacles

Reputation: 2855

There is currently no way to set a delay for the delivery of CloudKit push notifications. CloudKit delivers notifications at some point after a change occurs that satisfies a subscription. There is no app developer control of the timing of this process, and the timing may be impacted by multiple variables.

If you want to display a notification to the user at a later date, you could work around this by scheduling a Local Notification for that date (after you've received the CloudKit notification).

Alternatively, you could record the changed record / notification information in your app, and handle it as appropriate when the app is running.

Or, if you're willing to run your own server and/or send your own push notifications, the sky is the limit.

Upvotes: 1

Related Questions