TheCocoaProject / cordova-plugin-nativestorage

Cordova plugin: Native storage of variables in Android, iOS and Windows
http://thecocoaproject.github.io/
Apache License 2.0
292 stars 106 forks source link

Extend the plugin - addObserver #79

Closed Lechevallier closed 7 years ago

Lechevallier commented 7 years ago

Hi,

Thanks for this plugin, it's really usefull. I'm trying to implement the plugin to add an observer to some keys. I'm testing on the demo project, but it seems that my function is never called.

Which files should I edit when adding a new function? I'm editing files under the following location demo/plugins/cordova-plugin-nativestorage I added my function in src/ios/NativeStorage.m and its description in src/ios/NativeStorage.h.

- (void) addObserver: (CDInvokedURLCommand*) command { ... }

I also edited the file www/mainHandle.js by adding

StorageHandle.prototype.addObserver = function(reference, success, error) { ... };

And finally the file index.js of course

NativeStorage.addObserver(key, function (result) { ... }, function (e) { ... });

After calling this function, I'm supposed to get an alert of confirmation (or error), but it never came out. I also placed some NSLog which are not printed. So my function is not called. Did I miss one file to edit?

Best regards

GillesC commented 7 years ago

Hello

It seems that you have edited the right files (for the iOS part). The problem with logging in iOS is often solved by using the console plugin: cordova plugin add cordova-plugin-console

Are the functions correclty invoked in JavaScript?

Lechevallier commented 7 years ago

I build my project in the console (cordova build ios) but I run the project with XCode, so I can directly see the logs.

I tried to use the XCode debugger but its a mess.

I'm sure that the program run into the function where I called

NativeStorage.addObserver(key, function (result) { ... }, function (e) { ... });

But then no alert are displayed, as this does:

NativeStorage.putInt(key, function (result) { ... }, function (e) { ... });

Lechevallier commented 7 years ago

I fixed it, I was not editing the right file. Instead of this one demo/plugins/cordova-plugin-nativestorage/www/mainHandle.js edit this one demo/platforms/ios/www/plugins/cordova-plugin-nativestorage/www/mainHandle.js, at least for testing.

GillesC commented 7 years ago

Glad it worked!