We want to be able to send a notification to the device when our app is terminated on user's device (not paused).
On iOS this is when you double click the home button and swipe up on the app, and Android this happens then you press the Menu button and swipe the app to the right.
In Cordova, there are the following events:
deviceready
pause
resume
backbutton
menubutton
searchbutton
startcallbutton
endcallbutton
volumedownbutton
volumeupbutton
activated
None of these events will fire when the app is terminated. The closest event is pause, this is fired when the app is terminated, but also when the app is moved into the background, and there isn't a way to tell which one is happening. Plus any processes that need to happen will only happen when the app is un-paused later.
My question is, how can my server know (or be notified) when you have terminated the app, in a reliable way. In order for me to be able to send a push notification.
This is not possible on iOS; the operating system may signal in advance with a low memory warning, but that doesn't mean the app will be terminated.
On Android, Cordova does not offer any support natively for this. You might be able to accomplish something with plugins and the information here: How to handle code when app is killed by swiping in android?
Related
I'm working on a react-native app that is closed the majority of the time. However, I need to be able to send updates from the backend to different clients so they can update local geofences.
I figured I could use silent push notifications for this (using FCM). This appears to work fine when the app is running (either in the foreground or background), but when the app is closed, I am unable to handle these push notifications.
I'm able to handle normal push notifications while the app is closed, because when the user presses the notification, the app is launched and the notification is available as the initial notification, but this isn't an option with silent notifications.
Is there any way to have my app handle silent push notifications while closed? Either by opening in the background, handling the notification, and closing or by registering some kind of background service?
You may want to take a look at react-native-push-notification#silent
Basically for android:
If your Android app is not running when a silent notification is received then this library will start it. It will be started in the background however, and if the OS starts your app in this way it will not start the react-native lifecycle. This means that if your notification delivery code relies on the react-native lifecycle then it will not get invoked in this situation. You need to structure your app in such a way that PushNotification.configure gets called as a side effect of merely importing the root index.android.js file.
And IOS:
The crucial bit of an iOS silent notification is presence of the "content-available": 1 field.
Good morning
I'm developing a cordova application for my internship.
The application tracks the position of the user and does some logic with it to generate data the user needs.
This all works fine but the application needs to run as long as the user has a button on the main screen enabled
but right now when the application is running and you enabled the button which makes the application track the data. Then when the screen is turned off the application gets turned off and doesnt track the users position anymore.
I presume the application is suspended but then when you open the application again it is like you opened the application for the first time. (button turned off)
Is there a way to keep the application active? i know in native android you can write a service which does this but i need something that works with cordova
thanks in advance for the help
regards
bavo
I'm developing a web app that shows a counter, and when the counter comes down to 0 I want to notify the user(The counter is on a server, so there won't be a problem with reloading the page).
If the user is on a computer, I'm using a popup for the notification, but if the user is on an Android device, I would like the notification to be shown even if the browser isn't open.(I'm using AngularJS if that would be any help)
Is there a way to do this? I rather not build a special Android app.
Thanks.
//G
I'm afraid no, there is no way to do that. When any android application is not active is... not active, frozen. The browser is not a service, so as far as I know it won't process anything while in background. Even it's possible the OS close the browser if it needs more memory than is available.
My PhoneGap application need to emit a websocket (to update the connection status) message to the server when the "pause" event is captured.
Android
With Android device there is no problem by using this piece of code :
document.addEventListener("deviceready",function(){
document.addEventListener("pause", function() {
socket.emit('changeStatus', 'incative');
});
document.addEventListener("resume", function() {
socket.emit('changeStatus', 'active');
});
}, false);
iOs
In iOs this is a different kettle of fish. Indeed here is the official PhoneGap documentation about the "pause" event :
iOS Quirks
In the pause handler, any calls that go through Objective-C will not work, nor will any calls that are interactive, like alerts. This means that you cannot call console.log (and its variants), or any calls from Plugins or the PhoneGap API. These will only be processed when the app resumes (processed on the next run-loop).
When they say "calls that go through Objective-C will not work", are they talking about using network access ?
Indeed when I test my app on iOs my "changeStatus" message with the value "inactive" is send when I resume my application.
Here is my second question : Is it possible in phonegap iOs app to access the server after capture a "pause" event ?
Thanks for your help
I dont think it's possible because of several security issues on iOS.
As alternative solution, you can run an echo function at socket server end, which will continuously emit message to that particular user at a particular intervals. If user responds to that message, you can consider that user as a active user else consider him as inactive user.
It's also not a good practice for user to send his activity status. Consider what will happen if user lost his connectivity? You will never come to know if he is active orsleeping..
Hence its better to check it by ping at server end..
On button click I want to go back to the last running app, just like the back button on android or Alt+Tab. Is there a way to do that?
There is no programmatic way to the last running app specifically. However, if you know what the app is, you can activate it using a protocol handler, if it has one. E.g. If you got activated because of some flow, and you know you want to return to AppB, and AppB supports a protocol, you can use the launcher API to launch: "Appb://foo", and that app will open.