I'm using Phonegap Cordova and have an iOS app and web app that sync information to each other, the problem I'm having though is that if the user has the iOS open on their device, but minimized, the data doesn't update realtime. So if they add something on the web app and look at the iOS app the changes wouldn't have been made on the iOS side so they'd have to close the app and relaunch. This isn't very user friendly.
Would anyone have any advice how to fix this? Perhaps refresh the app every time they open, or scroll up to refresh manually?
Any help would be great! Thank you.
use this plugin :
cordova-plugin-background
and in index use this code for refrech the app
document.addEventListener('deviceready', function () {
cordova.plugins.backgroundMode.enable();
cordova.plugins.backgroundMode.onactivate = function () {
setInterval(function () {
location.reload();
}, 10000);
}
}, false);
you app it' well refrech in backround every 10000 second you can change the time
You definitely have a few options here:
You can use Cordova's resume event which should fire when the user brings the app back to the foreground (at least I think that's what it does, I haven't used that event myself)
If it applies to your use case, you could use the push plugin to push data to your device and trigger updates
A manual slide down to refresh would also be good, maybe even on top of the options above
Related
I need to restrict one my functionality with a timer. So I am using react-native-background-timer plugin for that. In case of android, its working fine and I am getting my expected output. But in case of IOS it working only when app is in foreground, when I press home button after 4-5 seconds this plugin timer also gets paused. I have followed all instructions mentioned in this plugin. Still no luck.
Here is my code:-
BackgroundTimer.start();
setInterval(() => {
// Here I am writing my business logic
//Which works properly in case of foreground.
}, 1000)
I am also added comment here to get implementation help.
Please let me know. Is I am doing anything wrong?
Also suggest any alternatives for my functionality.
You mentioned plugin is wroking fine, because it's using dispatchAsync method which is basically using in IOS to do small background work.
Check Usage Crossplatform section.
BackgroundTimer.runBackgroundTimer(() => {
console.log("Background Timer");
//Check above log will appear after every 3 seconds.
//Your timer reducing and updating code goes here
},
3000);
//Don't forget to remove Timer
//rest of code will be performing for iOS on background too
BackgroundTimer.stopBackgroundTimer();
I own an AngularJs app that I converted into a native app through Cordova.
The whole works on iOS (iphone), however I've just noticed that if I put the app on the background, then reopen/resume it, the application sometimes "freezes" for about 5 seconds then works.
No scrolling, no click events, for 5 seconds.
Any known reason to this? How to avoid it? It's very frustrating.
I found the code causing the issue:
document.addEventListener("resume", function () {
$rootScope.$broadcast('retrieveAllNotifications', null);
}, false);
So, according to the documentation:
Interactive functions like alert() when the resume event fires will
need to be wrapped in a setTimeout call with a timeout value of zero,
or else the app will hang. e.g.
So I transformed to:
document.addEventListener("resume", function () {
$timeout(function () {
$rootScope.$broadcast('retrieveAllNotifications', null);
}, 0);
}, false);
but it still hangs.
However, when I remove the broadcast, it works.
How to fix it? Increasing the timeout to 1 second for instance?
Actually, I noticed that I retrieved more than 500 notifications that are displayed (though hidden) in HTML.
What I've done is to delete a lot of notifications, and I noticed no more freeze.
It was just too heavy for the phonegap app to display 500 notifications at once without freezing.
How to run web service without open application
I need to run an service without open the app.
Once app closed from background also it must be run service.
Its an security app like anti theft functionality.
Can anybody help to run service without open app ?
As far as I know you can not, from a browser, check if an app is installed or not.
But you can try redirecting the phone to the app, and if nothing happens redirect the phone to a specified page, like this:
setTimeout(function (){
window.location = "https://itunes.apple.com/appdir";
}, 25);
window.location = "appname://";
If the second line of code gives a result then the first row is never executed.
Hope this helps!
You can check the "Implementing long-running background tasks" section from Apple document.
or
You can use by local notification to do that. But this not check every time. You set the time to where you will check a particular event.
Here is the tutorial for creating Local Notification step by step.
What is the best practise for telling your application to close when hosting it with Trigger.IO?
I want a button on the front to exit the application... I heard that for Android navigator.app.exitApp(); works, but got an error saying exitApp() didnt exit, but am hoping there is a more cross browser solution.
You can use forge.event.backPressed to listen for back button presses, and optionally quit the app there. E.g.:
forge.event.backPressed.preventDefault(function () {
forge.event.backPressed.addListener(function (closeMe) {
closeMe(); // this closes the app
});
});
James posted the documented method of closing the app, but the internal method can also be called like this:
forge.internal.call('event.backPressed_closeApplication');
This method is confirmed to work on Android, unsure whether it will work on iOS.
Ok so I have my first little app in JQ Mobile along with phonegap. Basically it just logs into a remote server if it authenticates it moves to an upload page.
What I would like to do when the app is closed is send the app back to the login page. This way they have to log in everytime they use the app.
Is there a function like on app close or something? Or is there a better solution to doing this?
Thanks guys.
Whenever the phone is closed, the pause event is fired.
To handle this event, you can do something like this:
document.addEventListener("pause", onPause, false);
function onPause() {
// Handle the pause event
}
Here is a more complete example in the PhoneGap docs.