XFawkes
XFawkes

Reputation: 383

Can I block receiving iOS Push Notifications during specified hours (night time) programmatically in Swift

my client wants to have an UISwitch control in Settings view in his app which is: 'Disable Notifications during night time'. He would like pushes that his API will be sending to mobile to be ignored if this option is turned on and it's a night time. Is this possible? I know that I can register and unregister for remote notifications, but this requires an App to be turned on. Is it possible to have it working like he wants?

Upvotes: 0

Views: 1285

Answers (2)

Chris Deck
Chris Deck

Reputation: 146

The only way to do this is to have a configuration in the back-end. Notifications are sent from a server, and only handled in the app. There is no way, besides unregistering the phone from receiving notifications, to have the phone deny a notification in a certain time frame.

The user can set a time preference in the app, send it to the server, and have the server do a check so it only sends the notification to the user in the preferred time period.

Check out this 3rd party repo to send your push notifications and just write in your own check before pushing the notification.

https://github.com/nomad/houston

Upvotes: 2

Alejandro Viquez
Alejandro Viquez

Reputation: 163

You can register or unregister for push notifications, i hope in your code switch you can make something like this:

let application = UIApplication.shared
//Didnt receive push
application.unregisterForRemoteNotifications()

//Receive push
application.registerForRemoteNotifications()

and if your client wants make this in Backend you can put a value on some database table with field receive:Bool, and the backend just take all the receive == true to send push notification on this devices

Upvotes: 0

Related Questions