We have a pretty common usecase with our (via Capacitor) Android generated app:
Once it receives a message via e.g. a Websocket (or third party apps like OneSignal, Firebase etc) we want to bring the app to the foreground in case the user is currently interacting with other apps (like Skype, Whatsapp etc). The reason is that we have implemented an "Alarm" scenario and if an alarm comes in, the app should come to front and show what's going on. Simple push notifications won't do the job here.
So we researched on the topic but as we're not native Android devs, we don't understand the full picture clearly.
e.g. Android bring app to foreground on Firebase notification suggests that via FLAG_ACTIVITY_REORDER_TO_FRONT it is possible to bring an app from the background to foreground.
The question is how is this going to be implemented in a hybrid app scenario (like with Cordova/IONIC/Capacitor).
In our app we are pretty far to listen to API signals via Websocket. Once an alarm is received we are able to send a signal to the App via Websocket so we can do pretty much anything. We could for example redirect the signal from the webapp back to the app container.
The question now is how can this scenario be solved either via Websocket or Firebase (FCM) and is it possible to solve it straight through the IONIC architecture?
In a cordova/ionic hybrid app I would use the cordova background mode plugin and the window_system_alert permission plugin. Those two are what I'm using and its working like a charm.
The steps I'd follow:
The first one was to include the force-start to the notification body
The second one was to give permissions to the app to be drawn over other apps. I managed to to this using this plugin: https://github.com/wryel/cordova-plugin-system-alert-window-permission. It requests the SYSTEM_ALERT_WINDOW permission.
The last one is to install the background-mode plugin (https://github.com/katzer/cordova-plugin-background-mode) and whenever you receive a notification you wake up the terminal and show your app in foreground (enable -> unlock -> moveToForeground).
Please, let me know if I misunderstood something and I can change my answer.
Related
I am creating a native social app which includes features such as Direct Messages, Voice and Video Calls etc and I have been trying to find a way to be able to receive data payloads from Firebase Cloud Messaging containing values such that I create a custom notification based on the type values from the data payload eg for VOIP calls I’d like to set a remoteInput action to see if a person declines or accepts a call or for direct messages add a remoteInput action for a quick reply and so far I haven’t had any luck especially with background services not being allowed anymore ever since the release of Android 8.1. So I would like to know if there’s a workaround I’ve been missing or if it’s even possible and if it is how do these popular apps do it. Thank you in advance.
Its same as your mentioned, once after the release of 8.1 apps are now more strict in regarding the background running process. There are actually two insights I had received while developed some projects. 1) More the app is used by the user, the app is sort of whitelisted and can receive more notifications, i.e., the system actually tracks the frequency of app usage. 2) You have the possibility to ignore your app from battery optimization process hence more chance of background process to run.
We have been trying for the last two weeks to get a reliable solution to try and sync our app data with a server in the background. We have tried the Background fetch mechanism but due to the iOS restrictions on when it runs it is not a viable solution.
iOS does provide Remote Notifications (https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app?language=objc) that we would like to use as we can use the same mechanism on Android.
The issues is that when sending a type 2 notification CN1 only delivers the notification when the app is brought to the foreground by the user.
On Android I see there is a Build Hint for android.background_push_handling that allows the notifications to be sent to the app even if it is in the background.
Is there a similar build hint that we can use for iOS?
If not, is there a way then to override the application:didReceiveRemoteNotification:fetchCompletionHandler: method that fires when the Notification arrives so that we can forward it to our app?
You can use silent push notifications for that purpose. To send a silent push notification you just have to include "content-available" : 1" into the body of the notification. More info on that here: Apple docs-silent push notifications
You should bear in mind that this will only work when your app is in the background, it won't work when the app is killed. When the app is killed the only solution is standard push notifications, unless your app has VoIP functionality, in which case you are allowed to use PushKit framework (if you use it in an app without VoIP functionality, you won't get pass the AppStore).
I successfully implemented the Firebase Unity SDK for notifications (sent by a cloud function). My understanding of notifications is that it should not end up in the notification tray at all if the app is open and takes it (it has data and notification portion), however in fact all notifications pile up in the tray. I managed to provide a CollapseKey and according message tag to at least have just the latest one show up there, however as long as the app is in the foreground (also when device goes to sleep) there is actually no point in notifying via tray.
So what I would like to do is to actively remove any notification on app start or recovery from pausing/sleeping. Is that somehow possible? I haven't found any API within the Unity SDK.
Thanks, habitoti
It looks like this is an issue on Android proper as well, and there's already a good Stack Overflow post on it. If you're unable or uncomfortable with writing a native Android plugin (I actually create an Android messaging plugin in this article as an example), I think I have a pure Unity solution.
First, you will need to pull in the Mobile Notifications package (the documentation is for a preview, but it looks like 1.0.3 is stable).
Then you should be able to call CancellAllNotifications as listed here. It's a static function, so all the code you should need is:
AndroidNotificationCenter.CancellAllNotifications();
LMK if that works for you!
--Patrick
I'm implementing an app with an internal calendar, fetched from a remote web service. I want to send a local notification to the user when an event of interest is scheduled in the calendar, at a specific time chosen by him. Just like the iOS calendar app, when you can create an event and ask to be notified X hours/days before it happens. The main difference is that you can't create events: they are downloaded from a pre-populated remote calendar.
In Android I've solved the problem by using AlarmManager, while in iOS with Swift 3 the closest I've got to porting the same solution was via opportunistic background data fetch. The main difference between the two solutions is that background data fetch doesn't work when the app has been killed.
It would be really important for me that local notifications worked even when the app is killed. I think users expect apps notifications to work even when the app is closed, like it happens with WhatsApp or Facebook. I know that those notifications are triggered by someone writing something and therefore they are Push Notifications, but the average user just expects notifications to keep working even when the app is closed.
What would be the most elegant solution to "emulate" the behaviour of Android's AlarmManager in iOS?
Scheduling a bunch of notifications in advance hoping that the user will eventually open the app before all of them are dequeued looks a badly designed solution.
Also, delegating all the work to the server and push the notifications to the subscribed devices looks quite bad too as it requires much more work on the server side. Plus it requires a server which is able to awake itself to send push notifications, which is something that I don't have. I only have a simple webserver which answers to HTTP requests.
EDIT : The ideal solution I'm looking for isn't any of the previous 2 options, since I find them more like workarounds than actual elegant solutions to what I perceive being a fairly common problem. There has to be a third option...
In iOS there is no way to achieve this. Looking at the documentation of application(_:didReceiveRemoteNotification:fetchCompletionHandler:), it states that
the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
You can receive push notifications, but no code will be executed until the user launches your app. So unless you are sending remote push notifications from a server, you cannot set up new local notifications until the user opens your app.
I'm developing viber like application using the ionic framework.
I want my app to be able to receive calls even when its on the background, just like whatsapp, the incoming call screen will pop up even if whatsapp is on the background or even when there is no instance of it at all.
I wasn't able to find anything about it.
I'm afraid there's no other way to achive this, then using Google Cloud Messaging (GCM). Although there may be other services that do the same.
When using GCM, your app will be notified with a notification even if it is not running.
But be careful! As your using Ionic, you will most likely rely on a cordova plugin to receive the notifications that are pushed to your device via GCM.
It depends on the chosen plugin how it handles the incoming notification.