How should I change how a remote notification is presented in iOS before the system presents it? In fact, silence it. There are times where my app has canceled a Firebase topic subscription locally, but that cancellation is not delivered to the server in time. So, when our app is not running(in the background OR NOT RUNNING AT ALL), the server would still send a message to that Firebase topic and iOS will receive it.
My question is, how can I intercept a notification, and check whether it should be presented and silent it if needed? I need to support iOS 9 as well so UNNotificationServiceExtension does not suit my needs.
Thanks.
That's a great question and currently there is no solution for this problem o iOS.
You can read about this on the Apple guide for local and push notifications.
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/
PS: If by silent you meant change the sound that the notification makes, you can do it. https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ModifyingNotifications.html#//apple_ref/doc/uid/TP40008194-CH16-SW1
Related
I'm using react-native-firebase for getting new notification
I would like to send from fcm data-only message, but i can't save this data when IOS app is closed or in background.
For android the solution is 'Headless JS', so if someone know any solution like Headless JS for IOS it's will be helpful.
https://rnfirebase.io/docs/v5.x.x/messaging/introduction
I was looking for IOS background services but all of them working every some minutes and i need to be a real time app
I believe what you are trying to achieve is a silent notification. To achieve this you need to send content_available as true in your FCM payload.
However, as mentioned in the documentation:
"Note that silent notifications in APNs are not guaranteed to be delivered, and can depend on factors such as the user turning on Low Power Mode, force quitting the app, etc"
Refer this SO question for more details on how to achieve silent notifications.
I have an application which has communication with a remote server. The server should push data into it using remote notification silently, and I need to get and store these data into a CoreData database. The user won't be aware of the whole process.
I can successfully get notified when the app receives a remote notification, while it is either in the foreground or background mode. However, I need to get data while the app is terminated as well.
I searched for the possible solutions. For example, this SO question was good if I don't tend to use silent notification. I also saw the PushKit capability, but I am not sure about the Apple Review result.
What is the possible solution?
If I want to use VoIP and PushKit to get notified when the app is terminated, would Apple reject my application?
If you’re not creating a VoIP app and you want your app to be in the App Store then the correct answer is: it is not possible. The only thing that can be done is adjusting your requirements in some way.
For instance you can send some notifications that will be visible for user in the Notification Center and wait until the user taps the notification or starts the app the usual way. Then the app will be able to do all the operations you need.
The delivery of push notifications is not guaranteed, so you should not rely on them to synchronise data.
For example, if multiple push notifications are sent while the device is offline, only the last notification is delivered when the device comes back online; the earlier notifications are lost.
When your app launches one of the first things it should do is check with your server for new data.
Since push notifications may not be delivered sometimes (you can lose a few of them), you can not run code after the iPhone is turned on to check if there is new information available from the server, and you can not run code if your iOS App is closed... What can you do if you want to be as more accurate as possible in for example a Chat App in iOS?
I mean, inform the user as faster as possible that he has new info available. Comparisons: WhatsApp is updated without any delay.
You can do background fetch if your App is in background. But if the App is closed and you miss a push, it's not going to be up to date until the next push arrives or user opens the App. The same with silent notifications. If the app is terminated by the user, you are not going to receive it. Is there any way to solve it? It must be because other Apps do it... If there is any "private and secret" API that they are using (I read about this answer when no one know how to do that)... Is there any way to apply to use it?
UPDATE:
I'm using push notifications. The goal is to fix when a push doesn't arrive. Example: User A send chat message to user B. User B doesn't have the App open. The system lose the push. User B is not going to receive the message until he open the App.
Push notifications seems to be your only way even if you do loose a few of them, which I don't know how you would since they are pushed to apples secure server... but what do I know. As long as the user turns on the push notifications you should be fine. They may be delayed due to apples way of handling them. Honestly push seems to be the future, having your app constantly every minute or two check for new messages is a huge battery water in conjunction with normal texting apps. Your app should provide the best live data but since apple restricts to push notifications when the app is off or not running just stick to push notifications and only push major events to the user. I believe you can set up a job scheduler using quartz or schedulator to setup your server to push notifications to your app.
I was curious if on the iPhone in general (or via iOS simulator) there was some way to see what "push notifications" are queued up?
I googled and find some information on how push notifications are done, but not how they are queued up.
No. This is not possible.
Although, to achieve something like this, you can send a silent push notification to the device to start a content download handler.
This handler can then query your API to get all necessary data and schedule a local notification. See this programming guide here for details.
You can also use this mechanism to remove obsolete notifications from the background if, for example, a web-version of the app flagged the information as read.
EDIT
The simulator is not capable of handling push notifications at all.
I face the following weird problem. I have a setup for notifications using Azure NotificationHub and Xamarin to develop an iOS app. It works fine with the following exception. Some times some notifications sent from my backend server (C# Visual Studio Windows Form Application) cause the iPhone to flash, I hear the notification sound, no notification is shown and older notifications of my app are removed from the list. Any idea what might be causing this?
Thanks
I see that you write:
I hear the notification sound, no notification is shown and older notifications of my app are removed from the list.
If you hear the notification sound, that means that the neither the APNS nor the Azure Notification Hub is the problem, because you are actually receiving the notification on the device.
No notification is shown.
1.This means that either the implementation of your code is deciding to actually receive the notification and do nothing with it. Check t Receiving Push Notifications while in background
This could also mean that in settings you disabled all the notification balloons, alerts and other properties. Make sure your app has actually the proper settings to work with notifications. (Believe me, it happens) https://support.apple.com/en-us/HT201925
Older notifications of my app are removed from the list. First of all I do not understand how do you have notifications on the list (did you actually received notifications somehow?). In any case, the notifications are removed by code when you enter your app. Please review this question (iOS application: how to clear notifications?)
Please mark my answer correct if it helped you, if not. Please provide more code of your implementation so we can provide you a better answer.
Best Regards.