You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So Im rebuilding this iOS app with ionic and would like to migrate the old user data stored using NSUserDefaults. For example, the old app would store the username like this:
Well, the exception tells the line number thats crashing. Opened the mainHandle file and turns out to be when trying to parse the result data from the device.
I have debugged the plugin's ios code and it is indeed getting the data from the device storage. So the data exists and it's being returned fine. The problem comes when JS code tries to handle that using JSON.parse.
In my tests, lets say the stored value is username = '[email protected]', then the parsing will fail. But if i do setItem(username, "[email protected]"), then retrieve that, I get username = '"[email protected]"' (notice the double quotes included). So, seems that the plugin won't be able to retrieve values that are not JSON-parsable.
The text was updated successfully, but these errors were encountered:
So Im rebuilding this iOS app with ionic and would like to migrate the old user data stored using NSUserDefaults. For example, the old app would store the username like this:
[defaults setObject:user.username forKey:@"username"];
And Im trying to get that back using getItem:
this.nativeStorage.getItem('username').then( data => { console.log("USERNAME: ", data) }, error => { console.log("ERROR: ", JSON.stringify(error)) }
This crashes and produces the following error:
code: 5 (JSON_ERROR)
source: JS
exception: {"line":400,"column":25,"sourceURL":"http://10.10.1.6:8100/plugins/cordova-plugin-nativestorage/www/mainHandle.js"}
Well, the exception tells the line number thats crashing. Opened the mainHandle file and turns out to be when trying to parse the result data from the device.
try { obj = JSON.parse(data); success(obj); } catch (err) { error(new NativeStorageError(NativeStorageError.JSON_ERROR, "JS", err)); }
I have debugged the plugin's ios code and it is indeed getting the data from the device storage. So the data exists and it's being returned fine. The problem comes when JS code tries to handle that using JSON.parse.
In my tests, lets say the stored value is username = '[email protected]', then the parsing will fail. But if i do setItem(username, "[email protected]"), then retrieve that, I get username = '"[email protected]"' (notice the double quotes included). So, seems that the plugin won't be able to retrieve values that are not JSON-parsable.
The text was updated successfully, but these errors were encountered: