Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Undefined is not an object #4

Closed
Spierki opened this issue Oct 23, 2015 · 14 comments
Closed

Undefined is not an object #4

Spierki opened this issue Oct 23, 2015 · 14 comments

Comments

@Spierki
Copy link

Spierki commented Oct 23, 2015

Hello,

first thank you for your job, it's amazing to use cordova plugin directly in React !

I followed your tutorial and I'm able to use the barcodescanner.

But now, I'm trying to use de sqlite plugin : https://github.com/litehelpers/Cordova-sqlite-storage

I added the plugin but when I try to use it I have this error : undefined is not an objet (evaluating 'cordova.window.sqlitePlugin').

This is my piece of code :

var cordova = require('react-native-cordova-plugin');
class Database {
openDb() {
cordova.window.sqlitePlugin.openDatabase({name: "my.db", location: 2});
}
}

Thanks in advance,
Florian

@axemclion
Copy link
Owner

Note that this should not be cordova.window.sqlitePlugin. From the plugin, looks like the object is used as sqlitePlugin.openDatabase - meaning that the object is exposed on window object in Cordova. Hence, while using it in reactNative, it will be available as cordova.sqlitePlugin.openDatabase.

@Spierki
Copy link
Author

Spierki commented Oct 23, 2015

I tried it but still getting the same error.. "undefined is not an object (evalutating cordova.sqlitePlugin.openDatabase)"

@axemclion
Copy link
Owner

Looks like the case is incorrect - it seems to be called SQLitePlugin, so it would be used as cordova.SQLitePlugin

@Spierki
Copy link
Author

Spierki commented Oct 23, 2015

I saw that it's write like that in the plugin file too so I tried it and It's a little bit better, now in the error message I can find the parameter that I passed on the function call : "undefined is not an object (evalutating cordova.SQLitePlugin.openDatabase({name:"my.db",location:1})"

I also tried to call another function but I'm get the same kind of message

@axemclion
Copy link
Owner

Do you have a sample app that I could try ?

@Spierki
Copy link
Author

Spierki commented Oct 23, 2015

I just wrote a very little example. https://github.com/Spierki/ReactNative-SQlite-Example

@nikkool
Copy link

nikkool commented Nov 12, 2015

I can't seem to figure out how to pass a function call. I've been trying to use the camera plugin and tried many ways, 4 of which are as follows.

    if (source ==='Camera') {
        cordova.navigator.camera.getPicture(this.itWorked, (msg) => {this.itFailed(msg);},
           {sourceType : cordova.navigator.camera.PictureSourceType.CAMERA,
            encodingType: cordova.navigator.camera.EncodingType.JPEG,  targetWidth: 1280,  targetHeight: 720,
            destinationType: cordova.navigator.camera.DestinationType.DATA_URL})


    } else { /*use photoLibrary*/
      cordova.navigator.camera.getPicture((x) => {console.log(x);}, function (result) {console.log("Result: " + result);},
           {sourceType : cordova.navigator.camera.PictureSourceType.PHOTOLIBRARY,
             mediaType: cordova.navigator.camera.MediaType.PICTURE,
             destinationType: cordova.navigator.camera.DestinationType.DATA_URL})
    }

Can you point out what I'm doing wrong?

further I've defined itWorked and itFailed as functions, but they don't seem to get called:

  itWorked :   function(imageData: string){
      this.setState({imageData:imageData})
 },

  itFailed:  function(error: string){
    this.setState({error:error})

  },

@axemclion
Copy link
Owner

@nikkool
Do you have your full snippet that I can take a look at ? Also, i think it may make sense to open new bug for this.

@Spierki
Copy link
Author

Spierki commented Nov 13, 2015

@axemclion did you tried my code ?

@axemclion
Copy link
Owner

@Spierki I looked at your code and figured out what the issue is. Note that I am using the latest version of the sqlite plugin, and react-native-cordova-plugin@0.0.7

This issue is that the SQlitePlugin does not export the object. It simply assigns it to this in this line. While this refers to window in a cordova app and works perfectly fine, window does not exist in ReactNative. Hence, you do not have a handle to that object.

A way to fix it would be to modify the SQLitePlugin here and add a line that says module.exports=root.sqlitePlugin. We could send in a pull request to the plugin, since exporting is the right way to do it.

@axemclion
Copy link
Owner

I plan to close this issue in a couple of days. If you are not able to get it working, please respond to this thread, and we can look to see if there are other issues.

@brodycj
Copy link

brodycj commented Nov 17, 2015

For sqlite, I recommend that you use https://github.com/andpor/react-native-sqlite-storage. I cannot promise when storesafe/cordova-sqlite-storage#382 will be fixed. @axemclion I recommend that you close this since the functionality is already supported by andpor / react-native-sqlite-storage.

@axemclion
Copy link
Owner

@brodybits Sounds good - thanks. Closing this issue.

@Spierki
Copy link
Author

Spierki commented Nov 17, 2015

@axemclion I tried what you said and it's working thank you ! @brodybits The plugin you said looks like to be functionnal, thanks too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants