MHugh
MHugh

Reputation: 465

executing code in response to an iOS notification

I need to execute code when my iOS app receives a notification, without involving any user interaction.

if the notification is a silent (i.e. non alert) notification DidReceiveRemoteNotification() does fire in both background and foreground modes.

However, silent notifications are relatively low priority and delivery is not even guaranteed, so this is not a viable option for us; we need to use alert notifications.

If the notification is an alert notification, DidReceiveRemoteNotification() does fire when the app is in foreground mode. However, it does not fire in background mode.

How can I execute code in response to an alert notification, in background mode, without involving user interaction. Is this even possible?

Thanks.

Upvotes: 0

Views: 60

Answers (1)

Ali Adam
Ali Adam

Reputation: 331

You can combine both silent notification and alert notification on one JSON.

by adding "content-available" : 1 as following :-

{ "aps" : { "alert" : "Notification Title", "content-available" : 1 } }

This will show the alert notification as well as wake the APP to do work on background.

Upvotes: 1

Related Questions