Know if iOS notification was dismiss - ios

Is there any way to know if a local notification was dismiss from the Notification Center (for example by pressing the x button)?
Is it possible to get a list of all the notifications currently visible in the Notification Center?

No it's not possible to get list of notifications from any of APIs from Apple.
And no there is no feedback from ignored / closed notifications.
If you want to implement logic like that, I would propose to build this type of logic based on your own servers.
When you send a notification you keep information about it on server side.
When you open the app from notification (that it's doable) you send information to a server side.
When you open the app not from notification you can have a logic on a server side checking if there were any notification that were not confirmed from the last time you opened the application.
Keep in mind that notifications are not always delivered - it's not guarantee that user will get them and if use has notifications turned of for your application - all notifications will be treated as ignored.
To improve that logic you may want to send information about user permissions for notifications to your servers - which still is not guarantee that he didn't disable them in settings :(
Long story short - never ever build any of your application core functionality based on notifications.

Related

Who handles the notification in iOS? - really React Native

I have a doubt, I've searched and didn't find the answer, I have implemented notification in my app, is it possible to have a cancel notification in the app or it is only a system option?
When the user opens my app on the third screen it asks about sending notifications, but what if the user doesn't want to receive those notifications anymore, does he need to go to iOS settings or can I do this from the app?
Thanks for your time
If you've used react-native-push-notification or #react-native-community/push-notification-ios then there has a way to remove notification from notification center.
you can use this code to remove all natification
PushNotification.removeAllDeliveredNotifications();
Removes the specified notifications from Notification Center
PushNotification.removeDeliveredNotifications(identifiers);
check out official doc for more detail
packages:
https://www.npmjs.com/package/react-native-push-notification
https://www.npmjs.com/package/#react-native-community/push-notification-ios
If you no longer needed to receive notifications in your app, it's better to handle the logic in your backend. When the user denies permission, remove the push token from the server. If you only want to remove certain types of notifications, instead of removing tokens, you can set a flag on backend logic to enable/disable certain notifications.
If you really want to do this on the client-side, you can use data-only notifications of FCM or a similar kind, where you have the control to present notifications as local notifications. Basically, a background listener will be triggered when you receive a data-only notification and OS won't present notification. You need to create a local notification and present it according to the data you receive. Here you can add your logic to filter notifications based on User's choice

IOS/Android app custom push notification handling

I want to develop an app, but before I actually start developing, I've been doing some research so that i can be sure it's going to work in the way I'd like to do this.
You can imagine the app as a kind of news app, where the user can indicate whether he wants to receive push notifications, and may also indicate that he only wants to receive a push notification if it is in X distance from his current location.
And this is probally a problem on IOS, On android it would be no problem if a push notification came in to read the current position of the user and settings and then show the push notification or not.
As far as I've read this is a problem on iOS, the system receives the push and the app can not respond to it unless the user clicks on it.
Theres also another problem about closing an app on IOS, ideally a app should not be closed (swiped out) by the user because this would be a force close on IOS.
From ive seen most users still swipe out apps, and this would mean that my app cannot run background tasks anymore.
This is what i thougt about:
Send Silent push, app download data on the background -> Check if this meets the user settings, if so show a local notification. (30 sec time to handle, but do not know if it is possible to throw a local push here too.)
The app sends data on the background over the user's current position before sending a push, the server checks for which apps it should be sent (actually no solution, too much data usage as it may be that the user is only one Specific location, need a good server if the app is used on thousands of devices.).
Does anyone have any idea how to handle this problem?

Control which iOS notifications to display

We have iOS push notifications configured and running. However, we would like the user to select which categories are interesting to receive and which are not important and would like to omit receiving those notifications.
Is there any way to do this through Apple push notification itself rather than through the server sending the notifications? (We can change the sent JSON). Can the iPhone send which categories it would like to receive and which are not needed by registering them to Apple? Other choice, can we interrupt the push notification before being shown and decide whether it should be shown or not through a delegate? So far, I can't find an available method to do either.
Any help is appreciated
The short answer is not from the client side. If you want a solution that works 100% of the time you will need to do something on a server which only sends the types of push notifications the user subscribes to.
If your App is in background there is no concept of "categories" of PUSH notifications and you have no control over if they show up in the notification center.
You can examine inbound push when the App is in the foreground and decide on the basis of some meta data to display or not, but that is not a 100% solution.

iOS Reachability when app not running

a simple question: is it possible to get a message, notification or similar when the internet connection is available when app is killed or not running?
For my purpose, I need a way to synchronize all my notifications because APNs can send only the last message.
EDIT:
I'm wondering how some apps (e.g. whatsapp) are able to sync their notifications when the internet connection is up. If I kill whatsapp, I can receive multiple notification when internet connection is reachable, but the APNS server provides only last message and, for this case, I'm not able to send silent notification. If I should develop a chat application, what are the best practices to work with Apple notifications?
If you send a push notification with a title, text, sound and/or badge property while the app is suspended (was killed / force closed), the device will still receive it, e.g. will show the text as a notification, play a sound and/or change the badge count.
However, your app won't be launched or woken up in the background in this case, so you have no way to handle the notification before the user taps on it. (See this question:
Will iOS launch my app into the background if it was force-quit by the user?)
So if the app was force closed by the user, your only option is to send a notification to be displayed as it is and if the device is offline, only the last notification will be received and displayed by the device.
For more control, you could use silent push notifications to implement "push-to-sync". In this case, the push notification only signals that there is new data to be fetched. The app (if not force closed) loads the data from the server then and triggers local notifications with the right data in the right order. But this won't work, if the app was force closed.
Apple push notifications have a lot of restrictions, so you won't be able to implement a perfect solution. In my opinion, it's fine if the user gets only the last notification when the device gets online after being offline for a while. At least he is informed that there is a new message and after opening the app, he can see the other new messages too. For the "push-to-sync" scenario, I would say that the user has no right to expect that the app works as desired, if he force-quits it.
Push notifications were never intended to be used in the way they are used by a lot of apps by now. E.g. they shouldn't contain sensitive data such as a chat message. They were intended to inform the user that there is new data for the app, so he can launch it to see the new data. E.g. instead of sending the actual chat message text a push notification should just contain the text "You have a new message". Then, you don't have the problem you described. Of course this is a terrible solution in terms of usability.

How to "Group/Collapse" multiple notifications in the notification center if come from same converstation on iOS

On Android, when supplying the same id in two calls to NotificationManager.notify, only one notification will be shown in the notification drawer.
But how to do it on iOS
Thanks
Notifications on iOS are not designed to be grouped/collapsed or replaced by other notifications. Just check other messenger apps, the convention is to have a separate notification for each message, contrary to Android. Also a message doesn't get replaced by a new message in the same conversation. The functionality that Android provides here simply doesn't exist in iOS.
What you could do instead is, to send silent notifications ("push-to-sync") and handle the grouping/replacing on client side, since you have more control over local notifications (e.g. you can remove single local notifications, but not single remote notifications). But keep in mind, if the app was force quit, it won't be woken up to process the silent notification.
I think your best option is to stick to the convention and don't group/replace notifications.
about iOS you have to understand many things about the push notification
first it is not part of your app, in iOS it is separate application called notification centre that your app add itself to it so when APNS send a notification it send it to the notification centre in your iPhone not to your app.
so what you need to do will be in the server side not in the mobile side
for example let's say it is a chat application
the server side should check if the message is sent from the same user
the badge count should remain the same and not to notify APNS with new count
and also in the server side
the server will check if the message from the same user to send only sound notification not text or if the server got many message at once from the same user send the text with got many message from same user
but all of that is just work around as something like this is not provided yet in iOS may be in iOS9 as it become more open and not like previous versions
good luck

Resources