pouchdb not working on ios safari - android

I am trying to write a cordova application that uses pouchdb as offline DB (without sqlite). my app works from all browsers and from android but not ios. am not sure why is that and what to do to fi it! here is my code to initialise the db:
app.onDeviceReady = function() {
try {
console.log("starting db");
window.offline_db = new PouchDB('offline_db');
if (window.offline_db.adapter) {
console.log("db started!");
}
offline_db.get("op_settings", function(err, doc) {
if (err) {
return console.log(err);
}
console.log(doc);
});
} catch (e) {
console.log(e);
}};
this does not return the doc, even though when I save the doc it says it was saved successfully, it only gives a promise but no result.
Also on safari Mac I can see the db content in debugger, but on safari ios I dont have this tab under resources

It seems, that you have put your callback function on the place of options to be passed(optional):
PouchDB get
Please try
offline_db.get("op_settings", null, function(err, doc)
it should work.

Related

Linking.canOpenURL returns true for IOS and false for Android : React Native

I have a simple string "twist" being passed on from the backend which is not a urlimage of simulator
My code for linking is as follows
console.log(url);
let linkOpened = false;
Linking.canOpenURL(url).then((canOpen) => {
console.log("canOpen : ", canOpen);
if (canOpen) {
Linking.openURL(url);
linkOpened = true;
} else {
console.log("i am calling");
}
});
As we can see "twist" is a string and not a URL which cannot be opened.
The same code on android emulator returns false which is the correct result but true on IOS which is incorrect
IOS Watchman Output
None of the answers on github/stackoverflow/apple dev forums work for me
I have also added this in my info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twist</string>
<string>nothing</string>
</array>
Running on
XCODE 14
Node 165.13.0
Kindly assist me. :)
Linking on backend using
https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl
It is directly linking ios nsurl TO javascript string which is causing error
for now use following code and wait for there update
const url = 'twist:';
console.log(url);
let linkOpened = false;
if (url.search(':') != -1) {
console.log('url', url.search(':'));
try {
linkOpened = await Linking.canOpenURL(url);
} catch (error) {}
}
console.log('linkOpened', linkOpened);

Database doesn't exist/not being loaded in built app with Expo

for the last couple of months I've been working on my first app project with react native and Expo.
I'm ready to finally launch my app but I'm having one big issue: The app uses a premade sqlite database to read and update information, this database gets loaded into the app the first time it launches or if the version has been updated (via a simple variable). I tested the app with no issues via the Expo Client but, now that I'm trying it in a phone (via an apk) there's no db and I have no clue why it's not working
Here's the code that loads the db:
FileSystem.downloadAsync(
Asset.fromModule(require('../databases/programs.db')).uri,
`${FileSystem.documentDirectory}SQLite/programs-${version}.db`
).then(() => {
programsDB = SQLite.openDatabase(`programs-${version}.db`);
loadDB(loaded);
});
I have this in metro.config.js:
module.exports = {
resolver: {
blacklistRE: blacklist([/amplify\/#current-cloud-backend\/.*/]),
assetExts: ["db", "ttf", "png", "jpg"]
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
And this in app.json
"assetBundlePatterns": [
"src/library/assets/**/*",
"src/library/databases/*",
"src/library/fonts/*"
],
"packagerOpts": {
"assetExts": ["db"]
},
I've tried both with
require('../databases/programs.db'
and
require('library/databases/programs.db'
After the app tries to load stuff from the db I get the following error:
"Directory for /data/user/0/com.company.myApp/files/SQLite/programs-2020052401.db doesn't exist"
I also tried changing the source db to download from .db to .mp4 after an answer I read elsewhere but it doesn't do it either.
Any ideas? This is the last hurdle before I can finally launch my app.
SOLUTION
After tinkering with it to isolate the problem I ended up finding out that the issue was that the directory (SQLite) where the database is going to be saved in the devices wasn't being created with downloadAsync, which I would have known if I had read the docs more carefully.
I just had to make the directory first if it didn't exist and then it worked alright.
Here's how the coded ended up looking:
// Check if the directory where we are going to put the database exists
let dirInfo;
try {
dirInfo = await FileSystem.getInfoAsync(`${FileSystem.documentDirectory}SQLite`);
} catch(err) { Sentry.captureException(err) };
if (!dirInfo.exists) {
try {
await FileSystem.makeDirectoryAsync(`${FileSystem.documentDirectory}SQLite`, { intermediates: true });
} catch(err) { Sentry.captureException(err) }
};
// Downloads the db from the original file
// The db gets loaded as read only
FileSystem.downloadAsync(
Asset.fromModule(require('../databases/programs.db')).uri,
`${FileSystem.documentDirectory}SQLite/programs${version}.db`
).then(() => {
programsDB = SQLite.openDatabase(`programs${version}.db`); // We open our downloaded db
loadDB(loaded); // We load the db into the persist store
}).catch(err => Sentry.captureException(err));

Cordova Sqlite Database Error when Upgrading to 64 Bit

Due to the recent update from Google Play Store, advising that all apps must now be 64 bit Compliant to be served by the Play Store, I have attempted to update our Cordova Android application to 64 bit.
Following, Google's advice, we have determined that there is only one of our cordova plugins that is not 64 Bit Compliant. However, this is causing painful issues.
The plugin in question, was the cordova-sqlcipher-adapter. We relied on this to encrypt our SQLite databases and to serve the databases to the application. We have now removed the reliance on this plugin for the encryption aspect. Therefore, it frees us up to upgrade to 64 bit.
When attempting to upgrade this, we realised that this plugin is built upon another plugin, cordova-sqlite-storage which handles the opening databases and executing commands. Therefore, to simplify things, we removed the cordova-sqlcipher-adapter and added the cordova-sqlite-storage plugin to ensure no issues were raised from the cipher aspect.
When running the application, using the new plugin, at a 64 bit compliant version, the app errors when attempting to run queries on one of the databases.
The error returned is:
Error: a statement error callback did not return false: no such table: RNM_Setting (code 1): , while compiling: SELECT s.Value AS [Value] FROM <MYTABLE> s WHERE s.[Key] = <PARAM>
We have tried different versions but always end up with the same issue and cannot find another way to interact with SQLite databases from a Cordova Android Application.
We have confirmed that the database in question exists in the correct directory and is populated with data and the table in question. We have even pulled the database out and run the exact query on it which succeeds so it cannot be a database issue.
The code used to open the database is:
SQLiteWrapper.prototype.OpenDatabase = function () {
var self = this;
if (this.db === null && this.hasSqlite) {
this.db = window.sqlitePlugin.openDatabase({ name: this.dbName, iosDatabaseLocation: 'Documents' });
}
};
this.GetSettingValue = function (settingKey, successCallback, failCallback) {
var self = this;
try {
var sql = ["SELECT ",
" s.Value AS [Value] ",
"FROM ",
" <MYTABLE> s ",
"WHERE ",
" s.[Key] = ? "];
sql = sql.join("");
var params = [settingKey];
this.sql.GetSingleItem(sql, params, this.ReadSettingFromDb, successCallback, fail);
} catch (e) {
fail(e);
}
function fail(e) {
self.CallbackError(failCallback, "GetSettingValue", e);
};
}
SQLiteWrapper.prototype.GetSingleItem = function (sql, params, rowRead, successCallback, failCallback) {
var self = this;
try {
this.OpenDatabase();
this.db.transaction(function (tx) {
tx.executeSql(sql, params, executeSuccess, executeFail);
}, function (e) {
fail(e);
});
function executeSuccess(tx, rs) {
var item = null;
try {
if (rs.rows.length > 0) {
var row = rs.rows.item(0);
item = rowRead(row);
}
successCallback(item);
} catch (e) {
fail(e);
}
}
function executeFail(tx, e) {
fail(e);
}
} catch (e) {
fail(e);
}
function fail(e) {
self.CallbackError(failCallback, "GetSingleItem", e);
}
};
this.ReadSettingFromDb = function (row) {
return row.Value;
};
We are at a bit of a loss now as to how to interact with a SQLite database in a 64 Bit Compliant way. Any help to achieve this would be greatly appreciated.
When you've used a cipher-driver before, you either need to de-crypt the database or start over with a new one database. There might be a table RNM_Setting, but without decryption it behaves as if it would not exist. Ever tried opening that file on a computer with "DB Browser for SQLite" ?
Besides, your reasoning concerning 64 bit does not make much sense, simply because android-database-sqlcipher-ndk.jar has an arm64-v8a/libsqlcipher.so.

How to redirect to app from WebBrowser in Expo

I am currently working on a project on Android using the Expo client for react native. I am trying to open a webpage using WebBrowser, passing my app development URI to the website. The website basically just redirects to the given URI after 5 seconds. However it never seems to open anything. I've used almost the exact same code as here: https://github.com/expo/examples/tree/master/with-webbrowser-redirect. When I load this project into expo and run, it redirects fine. However, when I copy the code for the website and app into my own project, website opens and displays, but redirect does nothing. It just stays there. Here is the code for opening the browser.
_openBrowserAsync = async () => {
try {
this._addLinkingListener();
let result = await WebBrowser.openBrowserAsync(
'https://wexley-auth.firebaseapp.com/?linkingUri=exp://192.168.1.2:19000'
);
this._removeLinkingListener();
this.setState({ result });
} catch (error) {
alert(error);
console.log(error);
}
};
The linking listener never fires the callback which should dismiss the browser. My app URI should be exp://192.168.1.2:19000 as expo developer tools shows me this when I connect over LAN. Ive also tried using Linking.makeUrl() instead of sending URI in string manually. Neither method works for me. Relevant website code:
document.addEventListener("DOMContentLoaded", function(event) {
var links = document.querySelectorAll('a');
var baseUri='';
// Take the uri from the params
var qs = decodeURIComponent(document.location.search);
if (qs) {
baseUri = qs.split('?linkingUri=')[1];
}
var redirectInterval = setInterval(function() {
var countdown = document.querySelector('.countdown');
var t = parseInt(countdown.innerText, 10);
t -= 1;
if (t === 0) {
clearInterval(redirectInterval);
window.location.href = baseUri;
}
}, 1000);
});
Am I missing a step? Do I need to setup a scheme for opening my app or should this work out of the box? Am I using the wrong URI? I noticed that in the example code, the app.json has the following fields that my app.json doesn't have:
"scheme": "expo.examples.with-webbrowser-redirect",
"platforms": [
"android",
"ios"
]

Cordova Instascan - Cannot access video stream

I am working on Cordova app. I wannt to implement a qrcode reader. I tried plugins available in Cordova but they all are buggy and some doesnot provide preview of scanner/video on same screen.
So I decided to use instascan which is a js based library to be used with webcams. I used it and implemented it in a simple cordova app and its working.
Now I see preview of my scan (camera video which is currently being scanned) and it scans perfectly.
But later I merged that code with my actual Cordova app which uses Vue cli. Now I am getting:
Error: Cannot access video stream (NotReadableError)
This error is probably (as I read) due to Chrome's https policy. But the problem is, Cordova uses webview and another cordova app which is basic cordova instance with this plugin only is working perfectly.
My implementation:
mounted: function () {
var _this = this;
this.$ons.ready(function () { // this is ready event fired by Onsen UI when cordova's native APIs are loaded
var scanner = new Instascan.Scanner({
continuous: true,
mirror: false,
video: document.getElementById('scannerPreview'),
});
scanner.addListener('scan', function (content) {
alert('scan' + content);
});
Instascan.Camera.getCameras().then(function (cameras) {
if (cameras.length > 0) {
if (cameras.length === 1) {
scanner.start(cameras[0]);
} else {
scanner.start(cameras[1]);
}
scanner.start(cameras[0]);
} else {
alert('No cameras found.');
}
}).catch(function (e) {
alert(e);
});
});
},
first add the permissions plugin:
cordova plugin add cordova-plugin-permission
And then you must request the permits in the camera:
permissions.requestPermission(permissions.CAMERA, success, error);
function error() {
return false;
}
function success( status ) {
if( !status.hasPermission ) error();
return true;
}

Categories

Resources