Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Handle Push Notifications that are not Opened (iOS, Swift)

So I am running a Swift application and using Parse to handle my push notifications. So far everything is working as expected.

I am sending JSON objects through the push notifications and updating a local array from the data received. I am handling the data through the application: didReceiveRemoteNotification and sending a dictionary through userInfo.

This works perfectly when the app is open in the foreground. It also works great when the app is in the background and the user opens the Push Notification when it is displayed in the banner.

The JSON object is handled according to the application: didReceiveRemoteNotification code.

However, when the user does not open the notification, application: didReceiveRemoteNotification does not get run and my local array does not get updated.

How do I make sure every time a notification is sent the JSON object gets handled and updates my local array accordingly?

like image 220
Peter Meiners Avatar asked May 05 '15 08:05

Peter Meiners


People also ask

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.

How do you handle Silent push notifications?

There are two ways users can receive silent push notifications on Android. Users can long press on a notification to get an option to display notifications silently. Users can also enable silent notifications by heading to Settings > App & Notifications > Search for app and choose> Notifications, and turn it off.

Does an app need to be open for push notifications?

Push notifications do not require any additional app to be functional — the recipient can see the notification even if the app is not running. Almost every app offers an option for push notifications where the user can opt-out or opt-in to receive those notifications.

What is silent push notification in iOS?

Silent push notifications are simply notifications that mobile app users receive without any pings, alerts, or interruptions to the user. They arrive on the mobile device and sit in the notification tray until read or dismissed.


2 Answers

You can not get get response or JSON object from Notification until User click on it and either didReceiveRemoteNotification or didFinishLaunchingWithOptions method get invoke.

From ios8, you can set interactive notification, which is useful to interact direct from notification, without opening application in foreground.

HERE it the tutorial for interactive Notification.

May this help you.

like image 191
Viral Savaj Avatar answered Oct 05 '22 05:10

Viral Savaj


It is generally incorrect approach, you should not rely on push notifications, user may switch them off or due to some reasons they may not be delivered. Instead you should get new data always from your server. Read from the Apple Push Notification Service Guide:

Important: Delivery of notifications is a “best effort”, not guaranteed. It is not intended to deliver data to your app, only to notify the user that there is new data available

like image 23
Azat Avatar answered Oct 05 '22 06:10

Azat