indexedDB.open() takes around 10sec on iOS Safari - ios

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.

Related

Firestore local cache is stale when returning to mobile app - can I force a re-sync?

I'm watching a cloud firestore list for changes using query.onSnapshop in a react-native-firestore app, currently testing on iOS.
While my app is in the foreground, I can make data changes elsewhere (eg. in my companion web app) and the mobile app immediately updates as expected. Usually, if I make changes while the app is closed or offline, they get picked up no problem once it is re-opened or comes online again. Happy days.
However, sometimes, when the app is in the background (not closed, just some other apps have been used in the meantime), I'll make a change elsewhere (eg. add/delete a record which meets the query's criteria), then when I come back to the app, the list does not change - eg. it contains deleted records, or doesn't contain the new ones. Nothing I do on the app can change this - it remains out-of-sync, even if I make local changes, like editing one of the records (even a deleted one). Changing network conditions also does nothing (eg. switching airplane mode off/on again).
The only way the list will get back in sync is if I make another change elsewhere, while the app is still in the foreground, or if I force-close the app and re-open it again.
The issue seems to occur when connecting to both the emulator, and the actual firestore.
I don't think I'm doing anything fancy. Basically following the examples in the documentation:
import React, { useEffect, useState } from 'react';
import firestore from '#react-native-firebase/firestore';
const MyAssignments = (props) => {
const [records, setRecords] = useState([])
useEffect(() => {
const onSnapshot = (snapshot) => {
console.log(snapshot) // this IS triggered but data is stale
setRecords(snapshot)
}
return firestore()
.collection('assignments')
.where('assignedTo', 'array-contains', props.userId)
.onSnapshot(onSnapshot, console.error);
}, [props.userId]);
// render the list
return ...
}
I'm not sure if this is a general firestore issue, a react-native-firebase issue, an issue with the underlying firebase ios SDK, or just my own misunderstanding?
In either case, is there a way to force the local cache to re-sync programatically, ideally when the app regains focus? Or has anyone solved a similar issue or have any ideas what to try next?
Edit 1: Note the code example above is slightly simplified for readability, as parts are spread across a few files and typed with typescript. In reality, I'm using crashlytics.recordError(e) for error handling in production, but console logging, as above, in development.
Edit 2: To debug, I've tried the following:
Switch on debug logging:
import firebase from '#react-native-firebase/app';
firebase.firestore.setLogLevel('debug');
However, this gave no extra logs in my javascript console.
I found I could view native device logs by following this guide and then filtering for Firebase, like so: idevicesyslog --match Firebase
This still shows very few logs, so I don't think debug logging is switched on properly. However, it does log this error every time I foreground the app:
<Notice>: 8.9.1 - [Firebase/Firestore][I-FST000001] WatchStream (10c244d58) Stream error: 'Unavailable: Network connectivity changed'
This error happens every time though. Even when the onSnapshot successfully picks up changes

Refresh app every time user opens it

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

IONIC2 - app gets killed after some time even when using Background Geolocation

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.

Detecting Firebase connection state uses huge amount of memory in react-native app

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.

Blackberry Phonegap geolocation Issues

I'm having a problem when testing the geolocation API using the Blackberry devices. I'm using Phonegap 1.2.0 to build my app and I use the common HTML 5 geolocation API to get the location information.
I'm testing using Bold 9900 device on wi-fi and rarely I could get the lat long. Most of the time it returns time out error. Using the simulator, I get everything running smoothly, my google map shows up just fine. Even when I test using other devices like Torch 9860 on wi-fi, I have to retry many times until I get the lat long. On Bold 9900, it just time out all the time. I checked the device location service from the Settings and I actually could see that the device GPS working, the lat long were detected fine. This must be something wrong with the Blackberry devices, the exact same codes I have running fine on iPhone.
I tested using the SIM card as well to make sure is not the wi-fi causing the problem, but the same thing happens. It just can't get the lat long right away, only when you're lucky.
As recommended by Blackberry Webworks, I do not need to specify permissions or feature elements inside the config file. My code is just as simple as this one:
navigator.geolocation.getCurrentPosition(success, error, { maximumAge: 600000,
timeout: 10000, enableHighAccuracy: true });
var success = function(position) { // do something };
var error = function(e) { // do something };
Can someone help me on this?? Before I throw my Blackberry devices...

Resources