简体   繁体   中英

How to Clear the localStorage of a Cordova app for iOS Platform

I have a cordova app running on ios platform . The login ID and Password are being passed from the cordova side to the native side and the urls are being called . They are stored in the local storage .whenever Im logging out how do i delete the app data containing the login id and password .

you can use removeItem() for removing the credentials whenever users log out.

In your case it could be -

localStorage.removeItem("loginID");
localStorage.removeItem("password"); //Its not preferred to store passwords in localStorage. Not directly atleast.

UPDATE -

you can do clear() to remove the localStorage completely. just do -

localStorage.clear();

This is simple and efficient. You don't need any other native code to access and remove them explicitly.

If you want to remove items specifically (eg password) then you can use a loop to run through all elements and remove them like this -

function cleanLocalStorage() {
  for(key in localStorage) {
      if(key=="password" || key=="something") //optional condition..
         delete localStorage[key];
  }
}

See this answer for the path of LocalStorage Storage locations in the system - https://stackoverflow.com/a/27612275/5213405

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM