Comments (8)
The code you have looks right to me ..
Do you have the plugin cordova-plugin-file
installed?
from awesome-cordova-plugins.
Yes, the plugin is installed. Maybe the plugin is missing the equivalent of $cordovaFileError and $window ?
from awesome-cordova-plugins.
Hey @Fenkiou ..
I was looking at the plugin's source code. The function getFreeDiskSpace()
is not exposed in the plugin's JavaScript file. It is a function defined in the Java and Objective-C files only. Which explains why you aren't able to access it through the ionic-native wrapper you wrote.
Ref: https://github.com/apache/cordova-plugin-file/search?utf8=%E2%9C%93&q=getFreeDiskSpace
The ionic-native wrappers route your call to the plugin's methods that are defined in their JavaScript files (which is usually the methods they have documented).
You probably saw the method implemented in ngCordova and thought it's one of the plugin's methods. If you look at their code, they are actually executing the method using cordova.exec()
which speaks to the Java/Object-C files directly without passing by the JS file.
Ref: https://github.com/driftyco/ng-cordova/blob/master/src/plugins/file.js#L27-L35
We might be looking to implement a similar approach to that method when we add the file plugin.
from awesome-cordova-plugins.
Ok, I thought that ionic-native plugin wrap ngCordova plugin but it's the cordova plugin that is wrapped.
cordova.exec
is only used in getFreeDiskSpace(), and when I saw it, I tried to implement checkDir() method instead, like this :
@Cordova()
static checkDir(path: string, dir: string):Promise<any> {
let resolveFn, rejectFn;
let promise = new Promise((resolve, reject) => {resolveFn = resolve; rejectFn = reject; })
var directory = path + dir;
if ((/^\//.test(dir))) {
rejectFn('directory cannot start with \/');
}
try {
var directory = path + dir;
window.resolveLocalFileSystemURL(directory, function (fileSystem) {
if (fileSystem.isDirectory === true) {
resolveFn(fileSystem);
} else {
rejectFn({code: 13, message: 'input is not a directory'});
}
}, function (error) {
error.message = error.code;
rejectFn(error);
});
} catch (err) {
err.message = err.code;
rejectFn(err);
}
return promise;
}
But it's not working anyway. Even with just something like this :
@Cordova()
static checkDir(path: string, dir: string): string {
return "some string";
}
It's still raising an error on https://github.com/driftyco/ionic-native/blob/master/src/plugins/plugin.ts#L100 without tell me the error but it's this call that fails.
from awesome-cordova-plugins.
Adding the @Cordova()
decorator overrides anything that's defined in your function.
from awesome-cordova-plugins.
This should work.
static checkDir(path: string, dir: string):Promise<any> {
return new Promise((resolve, reject) => {
var directory = path + dir;
if ((/^\//.test(dir))) {
reject('directory cannot start with \/');
}
try {
var directory = path + dir;
window.resolveLocalFileSystemURL(directory, function (fileSystem) {
if (fileSystem.isDirectory === true) {
resolve(fileSystem);
} else {
reject({code: 13, message: 'input is not a directory'});
}
}, function (error) {
error.message = error.code;
reject(error);
});
} catch (err) {
err.message = err.code;
reject(err);
}
});
}
from awesome-cordova-plugins.
That's it, thank you ! I'll try to implement methods I need to see if it works and I hope get back with a PR.
UDPATE:
Your way to return promise causes a memory consumption issue, I used my way with @cordova() removed and it works.
from awesome-cordova-plugins.
@Fenkiou Thanks for feedback. Glad you got it working.
from awesome-cordova-plugins.
Related Issues (20)
- Wrong top package.json field 'main' HOT 1
- Screen orientation plugin don't lock screen on ios 17 HOT 1
- Where to find real documentations? HOT 1
- Plugin bluetooth-le>RespondParams Interface> Missing optional property: address HOT 1
- download PDF file from external website with inappbrowser HOT 1
- Avoid `any` type and use tsdoc comment properly. HOT 1
- [BLE] Missing method `requestConnectionPriority`. HOT 1
- Creating Cordova Plugin HOT 1
- Add interface to diagnostic plugin HOT 1
- @awesome-cordova-plugins/local-notifications: getAllScheduled and getAllTriggered not working in Cordova HOT 1
- Is there any Unity3D plugin? HOT 1
- Plugin for Google Nearby Connections HOT 1
- social-sharing :: not working on onePlus device when share mp4 video. HOT 1
- Exception calling Diagnostic.requestBluetoothAuthorization method HOT 1
- Cannot find plugin.xml
- requestConnectionPriority() is missing in BLE plugin HOT 1
- @awesome-cordova-plugins/media seems not to work at all HOT 1
- @ionic-native/in-app-purchase-2 isnt compatible with billingclient v5 as required by Google to update apps HOT 1
- Where is @ionic-native/sqlite in awesome-cordova-plugins? HOT 1
- Can you add cordova-plugin-autostart please
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome-cordova-plugins.