Skip to content

Commit

Permalink
fix importing protocols from Server on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed Dec 4, 2023
1 parent e6e02ff commit 9e98655
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
12 changes: 5 additions & 7 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget android-versionCode="6395" id="org.codaco.NetworkCanvasInterviewer6" ios-CFBundleIdentifier="org.codaco.networkCanvasInterviewerBusiness" ios-CFBundleVersion="6395" version="6.5.2"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget android-versionCode="6405" id="org.codaco.NetworkCanvasInterviewer6" ios-CFBundleIdentifier="org.codaco.networkCanvasInterviewerBusiness" ios-CFBundleVersion="6405" version="6.5.2" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Network Canvas Interviewer</name>
<description>
A tool for conducting Network Canvas Interviews.
</description>
<author email="[email protected]" href="http://coda.co">
Complex Data Collective
</author>
<content src="index.html"/>
<content src="http://192.168.1.210:3000/index.html"/>
<access origin="*"/>
<access origin="cdvfile://*"/>
<allow-intent href="http://*/*"/>
Expand All @@ -19,6 +16,7 @@
<hook src="scripts/cordova/after-run.js" type="after_run"/>
<hook src="scripts/cordova/before-prepare.js" type="before_prepare"/>
<platform name="android">
<preference name="scheme" value="http"/>
<allow-intent href="market:*"/>
<allow-navigation href="https://*/*"/>
<uses-permission android:name="android.permission.INTERNET"/>
Expand All @@ -40,6 +38,7 @@
</edit-config>
</platform>
<platform name="ios">
<allow-navigation href="*"/>
<allow-navigation href="*"/>
<allow-navigation href="*"/>
<preference name="WKWebViewOnly" value="true"/>
Expand Down Expand Up @@ -68,7 +67,6 @@
<icon height="1024" src="www/icons/ios/NC-Square-1024.png" width="1024"/>
<splash src="www/icons/ios/Default@2x~universal~anyany.png"/>
</platform>
<preference name="scheme" value="http"/>
<preference name="Orientation" value="landscape"/>
<preference name="target-device" value="tablet"/>
<preference name="DisallowOverscroll" value="true"/>
Expand All @@ -86,4 +84,4 @@
<plugin name="cordova-plugin-network-information" spec="~2.0.2"/>
<plugin name="cordova-plugin-chooser" spec="~1.3.1"/>
<plugin name="cordova-sqlite-storage" spec="6.0.0"/>
</widget>
</widget>
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,4 @@
"cordova-plugin-ionic-keyboard": {}
}
}
}
}
21 changes: 15 additions & 6 deletions src/utils/protocol/downloadProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const downloadProtocol = inEnvironment((environment) => {
if (environment === environments.ELECTRON) {
const request = require('request-promise-native');
const destination = path.join(tempDataPath(), getProtocolName());

return (uri, pairedServer = false) => {

let promisedResponse;
if (pairedServer) {
promisedResponse = new ApiClient(pairedServer).downloadProtocol(uri);
Expand All @@ -56,29 +56,38 @@ const downloadProtocol = inEnvironment((environment) => {
}

if (environment === environments.CORDOVA) {
const destination = `${tempDataPath()}${getProtocolName()}`
return (uri, pairedServer) => {
let promisedResponse;

if (pairedServer) {
// In cordova, the cordova-plugin-network-canvas-client wants the destination
// to be a folder, not a file. It assigns a temp filename itself.
const destination = tempDataPath();
promisedResponse = new ApiClient(pairedServer)
// .addTrustedCert() is not required, assuming we've just fetched the protocol list
.downloadProtocol(uri, destination)
.then(() => destination);
.then((result) => {
// Result is a FileEntry object
return result.nativeURL;
})
} else {
promisedResponse = getURL(uri)
.then(url => url.href)
.catch(urlError)
.then(href => new Promise((resolve, reject) => {
// The filetransfer plugin requires a folder to write to
const destinationWithFolder = `${tempDataPath()}${getProtocolName()}`;

const fileTransfer = new FileTransfer();
console.log('fileTransfer', destination);
fileTransfer.download(
href,
destination,
() => resolve(destination),
destinationWithFolder,
() => resolve(destinationWithFolder),
error => reject(error),
);
}));
}

return promisedResponse
.catch((error) => {
const getErrorMessage = ({ code }) => {
Expand Down

0 comments on commit 9e98655

Please sign in to comment.