LocalStorage is not working as expected in iphone/ipad with os 10

Hi ,

I am facing issue with localstorage in iphone/Ipad with os version 10 and above.

The scenario is like this.

First time When i open the application the localstorage key value is null . At that time i’m assigning value to that corresponding key.

second time When i open the application still localStorage key is null again assigning value to that corresponding key.

Third time when i open the application i’m getting value from localStorage . If i repeat above steps no.of time , everytime i’m able to get value from localstorage.

Here the problem is second time only with localStorage.

Below are the TechKnowledgies that i’m using
IBM Mobile First V7.1
Cordova V3.7
Ionic V1.2 and angular 1.4

How are you writing and reading values from LocalStorage? Are you using proper methods like getItem, setItem, and such?

Hi macondele,
Thanks for replay. Yes, i’m using those methods properly. Here is the sample code snippet.

if(localStorage && window.localStorage.getItem(“isFirst”) == “first”){
alert(“Data available”);

}else{
alert(“LocalStorage is empty”);
window.localStorage.setItem(“isFirst”, “first”);

}

Try
if (window.localStorage && window.localStorage.getItem("isFirst") === "first")
instead of
if (localStorage && window.localStorage.getItem("isFirst") == "first").

HI macondele,

Tried above solution getting same issue, Facing above issue in iphone & ipad with os version 10+. Same code working in fine in Iphone & ipad with os version 9 (below 10).

Try to see if the solution provided over here http://stackoverflow.com/a/39721482/7398456 solves your problem.

HI macondele,

Tried above solution , still facing same issue.

Did you find a solution? I’m having the same problem.

I would recommend never using window.localStorage for anything. For communication amongst disparate parts of a running app, use mutually injected services. For communication across app restarts, use Ionic Storage.