I have an IONIC2 app, which needs to wake up every morning at 8 AM for 20 minutes to send user reminders based on the user's geolocation.
I am using this plugin (which uses IOS significant changes API to monitor changes in user's location)
https://github.com/mauron85/cordova-plugin-background-geolocation
The problem:
The app doesn't get killed when I close the app and the background geolocation works for me fine for some time. I have tested upto an hour. But when I wake up next morning, I find the app was killed by IOS.
I know there is another plugin to keep the app running in the background https://github.com/katzer/cordova-plugin-background-mode, but I have read tons of complaints from people that it will cause your app to be rejected by the AppStore (In fact, the plugin has a disclaimer to the same effect too).
For waking up the app tomorrow, I simply set a setTimeout
setTimeout(function(){
console.log('waking up');
self.helper.scheduleLocalNotification('Hello World', 'Good Morning', 10, "");
self.ionViewDidEnter();
}, wakeupinMilliSeconds);
Here is my geolocation code:
setupBackGroundGeolocation(){
let config = {
desiredAccuracy: 100,
stationaryRadius: 50,
distanceFilter: 100,
interval: 5000,
pauseLocationUpdates: false,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
BackgroundGeolocation.configure((location) => {
console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
this.currentLocation.lat = location.latitude;
this.currentLocation.lng = location.longitude;
Promise.all([
//I do some calculations here.
]).then(d => {
// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
BackgroundGeolocation.finish(); // FOR IOS ONLY
});
}, (error) => {
console.log('BackgroundGeolocation error');
}, config);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
BackgroundGeolocation.start();
}
I don't use this plugin but had same symptons. I couldn't figure out what was wrong: no error messages, no clues but app kept closing after a few hours.
I guess there was something messed up after installing and uninstalling so many cordova plugins. Now the app is much more stable. I removed and added platform. That seemed to do the job.
I've been reading about ionic2 and performance. Among so many reasons, a possibility about low performance and crash is related not to unsubscribe from observables. Read about async pipe and .unsubscribe observables when component is destroyed ngOnDestroy
Another problem i found was a very basic mistake developing in angular. I loaded everything in the app module so this required lot of memory to load the entire app at once. I guess with slow terminals that can affect more. Anyway, basic angular concepts as .module files should be understood.
Related
I would like that my app could make a small api call to a server so that it checks if there is an update, the data is very small and it shouldn't require that much time to execute, if it fails, it's not a problem that will try the next 15 minutes. It will show a generic notification to the user, so that the real data update will be done when the app is loaded. I know how to do the notification part, but not the api call.
The app should do this call when it's in the background and even if the user closes it from the multitasking UI and auto start when the device is turned on but the app hasn't been opened once yet.
In Android you can archieve this with the AlarmManager but from what I understand there is no way for this on iOS other than remote push notifications?
In the iOS part, you can achieve it with Backgrounding with Tasks. However, iOS backgrounding is much more restrictive than on Android as there are only a few specific tasks that apps are allowed to do in the background (things like VOIP, audio, location, etc.). You can use a UIApplication background task to delay that suspension for a few minutes, but you can’t delay it indefinitely.
public override void DidEnterBackground (UIApplication application) {
nint taskID = UIApplication.SharedApplication.BeginBackgroundTask( () => {});
new Task ( () => {
DoWork();
UIApplication.SharedApplication.EndBackgroundTask(taskID);
}).Start();
}
The other approach is using remote notifications which means applications can register to receive notifications from a provider, and use the notification to kick off an update before the user opens the application.
I have an indexedDB database used in a web app on my iPhone.
Lately it started to take more time to start. After diagnosing this case for some time I've found that it happens because of indexedDB.open() running for 10+ seconds.
Here is a little code example
var db;
var promise = utils.promise();
var openRequest = indexedDB.open(this.dbName, this.version);
openRequest.onsuccess = function(evt) {
db = openRequest.result;
promise.resolve();
};
openRequest.onerror = function(evt) {
promise.reject();
onError(evt, 'Database open');
};
Database itself didn't change lately so much. Also I don't have lots of data. It has around 300 records.
Any idea how to diagnose such an issue?
UPD may be related https://bugs.chromium.org/p/chromium/issues/detail?id=402980
Apparently it was a result of iOS update (from 11.1.* to 11.2.*).
I have my web app added to the Home Screen. And as far as I understand when you do iOS updates the web app container is moved to a new iOS environment but conserves some features from the original iOS version (probably something related to WebView used for web app but I am not sure).
So I have added my web app to Home Screen again and it starts without delays.
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
When I add the following code to my react-native app, memory usage soars from 40MB to 400MB in ten minutes (and keeps going) as soon as I take the app offline.
root.child(".info/connected").on("value", (snap) => {
if (snap.val() === true) {
this.online = true;
info("Going online");
if (this.user) { /* counter already loaded */
debug("posting offline transactions");
}
} else {
this.online = false;
info("Going offline");
}
});
The app itself is entirely quiescent and the .on() listener is not getting triggered. When I bring the phone back online memory usage stabilizes but does not decrease.
I have no idea how to debug this. I cannot run the app under the Chrome debugger because the phone has to be online to connect to the debugger. I cannot use the iOS simulator because to bring that offline you have to bring the whole computer offline and then you get the error: WebSocket connection failed
The only way I have to debug is to view console.log messages in xcode and my app has lots of them, but nothing is happening in the app itself.
I need to monitor offline/online state in order to work around the fact that Firebase transactions consume a large amount of memory when the app is used offline.
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.