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

SyntaxError: Unexpected token when I call NativeStorage.getItem #60

Closed JimmyChung1991 closed 7 years ago

JimmyChung1991 commented 7 years ago

Hi, private void cordovaPreference() { // Log.i("jimmy","url"+url);

    SharedPreferences mySharedPreferences = getSharedPreferences(PREFS_NAME, Activity.MODE_WORLD_READABLE);

    SharedPreferences.Editor editor = mySharedPreferences.edit();
    editor.putString("reference", "12342345fasdfaf");

    editor.commit();
}

I store the reference in android Then I get it from ionic side. NativeStorage.getItem("reference") .then( data=>console.log("nativestoragesuccess"+data), error=>console.error("nativestorageerror"+error.exception) ); The strange thing is that when I put "reference", "12342345" or the value is just num. It's ok But editor.putString("reference", "12342345fasdfaf") or any value contains a-z .It show SyntaxError: Unexpected token f .I don't get it

GillesC commented 7 years ago

So you've tried to save a value in Android via putString and retrieve it via getItem in JS. I hope you've followed my 'instructions' here?

What works (?):

What doesn't work (?):

To be of better help, please provide me with more logging information related to the error, e.g. where is the exception thrown.

JimmyChung1991 commented 7 years ago

solved it Thanks,bro

GillesC commented 7 years ago

I'm glad it works now! Please consider explaining what the problem was, and how you solved it. This can come in handy for people with the same problems.