0

I'm developing an app using CORDOVA and I am using localstorage in javascript

Can I use Cordova to access local storage in webview directly?

I looked at the documentation on the https://cordova.apache.org/docs/en/latest/ but couldn't find it.


Javascript code -

 window.localStorage.setItem("test", "hello World");

ios native code - I want

              get("test");
Cpt Kitkat
  • 1,392
  • 4
  • 31
  • 50
ohj
  • 35
  • 5

1 Answers1

0

yes it works on ios in javascript, to get the value :

window.localStorage.getItem("test"); 

more from cordova docs https://cordova.apache.org/docs/fr/latest/cordova/storage/localstorage/localstorage.html :

   document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        window.localStorage.setItem("key", "value");
        var keyname = window.localStorage.key(i);
        // keyname is now equal to "key"
        var value = window.localStorage.getItem("key");
        // value is now equal to "value"
        window.localStorage.removeItem("key");
        window.localStorage.setItem("key2", "value2");
        window.localStorage.clear();
        // localStorage is now empty
    }

to read :

https://github.com/react-native-community/react-native-webview/issues/73

How to set the local storage before a UIWebView loading its initial request?

devseo
  • 1,182
  • 1
  • 13
  • 26
  • This is not native code... This is JavaScript code I want objective-c code – ohj Sep 05 '19 at 02:58
  • you can execute JS with evaluateJavascript function, please look at : https://stackoverflow.com/questions/46082813/ios-objective-c-localstore-in-wkwebview – devseo Sep 05 '19 at 06:57