View iOS Notification Queue? - ios

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.

Related

How does WhatsApp bypass APNS restriction to display multiple push messages received while device was offline?

While working with APNS, I was able to have push notifications work flawlessly while device is online.
For any APNS push I send while device is offline, only the last one is received once the device is back online. This seems to be coherent with Apple's Store-and-Forward design.
However - I did notice, that when sending WhatsApp messages to an offline device, once this device goes online it receives all push notifications (one for each message). This is not something based on collapse identifier, but rather independent push notification for each message.
So how did WhatsApp do it?
Tried using Notification Extension and attempt to post multiple local notifications, but this also fails as extensions are not allowed to do that.
Instead of a normal push notification, use a Background Notification, which will not show anything visible, but wake up your app in background. Use this event, to make api call, get relevant data and generate multiple local notifications.
Note the following from the documentation when you implement application(_:didReceiveRemoteNotification:fetchCompletionHandler:) :
system calls this method when your app is running in the foreground or background
system does not automatically launch your app if the user has force-quit it
you must call the block in the handler parameter (fetchCompletionHandler) or your app will be terminated. Your app
has up to 30 seconds of wall-clock time to process the notification
and call the specified completion handler block
Apps that use significant amounts of power when processing remote notifications may not always be woken up early to process future
notifications
Please read relevant documentation completely before making ANY assumptions about how you think this should work.

VoIP notifications in hybrid apps not working

Recently Apple changed its way of handling VoIP notifications. Now they force you to use CallKit in the same run loop in order not to throw your notification away. The trace I get is this one
Apps receving VoIP pushes must post an incoming call (via CallKit or IncomingCallNotifications) in the same run loop as pushRegistry:didReceiveIncomingPushWithPayload:forType:[withCompletionHandler:] without delay.
When you get this warning three times, the system is "dropping your notifications on the floor".
The problem here is that I'm developing a hybrid VoIP app using the phonegap-plugin-push, and I'm afraid that the on notification event is not fast enough (or at least not the same run loop) for iOS.
Did anyone face this issue?
I've thought of changing to regular push notifications, but I can't find a way to make my app relaunch when it's killed and execute some code (launch CallKit, for example).
Edit:
I'm trying this approach with push notifications and I already configured the background modes. I noticed that sending the "content-available" and some data, like "badge", or "alert" in the notification, the app is launched if it went to background recently. After 15 minutes in the background the push notification arrives but the app doesn't launch anymore
Thank you in advance.
Our app uses CallKit and push notifications, and it launches when a push notification arrives for a new incoming call. It has to be configured in the project build and run once to register with iOS for this, though.
I found a solution:
Since iOS changed its policy about handling voip push notifications, it forces you to report a new incoming call when receiving the voip: https://forums.developer.apple.com/thread/117939
This plugin does it: https://github.com/mattkhaw/cordova-plugin-callkit
It merges two plugins (WebsiteBeaver/CordovaCall and Hitman666/cordova-ios-voip-push). It worked for me. I just had to remove the receiveCall from the javascript and tweak a little bit the plugin.
The methods related to the voip notifications register are in the cordovaCall class, so it is pretty straightforward to work with.

How to change how a remote notification is presented before presentation?

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

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.

Can iOS notification push a file

Can I somehow send a whole file with a push notification on iOS, or send a notification to a device to download a file from a server.
The device NEEDS to do that on it's OWN, without user interaction and I need it to work without updating the app in the store.
So is that possible? If not any advices/alternatives are welcome.
Can I somehow send a whole file with a push notification on iOS
While you could serialize your file and send it, push notifications are limited to 2kB.
or send a notification to a device to download a file from a server.
You can do it with "Remote notifications" background mode.
The device NEEDS to do that on it's OWN, without user interaction
The previous option will work, unless your user manually killed your app.
I need it to work without updating the app in the store.
You will need to update your app. At least to turn on "Remote notifications" background mode and handle the incoming data.
EDIT:
And don't forget that Push Notifications are NOT RELIABLE!
A Push notification can be delayed or even never distributed. That's why you should NEVER rely on it to achieve any critical work.
No, you cannot push an entire file given that a push notification is limited in size to 2KB (256 bytes in pre-iOS8). It is possible to cause an app to execute code using a push notificiation.
Depending on the type of app, it might be able to ocassionally poll your server and retrieve information. All in all, you will certainly have to make changes to your app's code, thereby requiring you to publish a new version on the App Store.
Can I somehow send a whole file with a push notification on iOS
NO
You can learn more about Push Notifications and get answers to other questions here
How we leverage iOS push notifications

Resources