2013-02-06 3 views
3

iOS 독립 실행 형 웹 응용 프로그램 (apple-mobile-web-app-capable 등 사용)에서 간단한 데이터를 보관할 필요가 있습니다. 데이터는 사용자가 사이트를 방문 할 때 정의되고 localStorage.name 등으로 저장됩니다. 동일한 페이지가 "홈 화면에 저장"되지만 도착하면 localStorage.name 등을 출력하면 undefined을 반환합니다.LocalStorage가 독립 실행 형 웹 응용 프로그램에 전달되지 않음

Safari로 돌아가서 정보를 여전히 알고 있습니다. 내 랩톱의 개발자 콘솔로 가져 오면 모든 데이터를 가져올 수 있습니다. 다른 도메인이나 다른 것은 말할 것도없고 다른 페이지가 아닙니다. 내가 읽은 모든 것은 localStorage (Safari와 독립 실행 형 응용 프로그램간에 공유 할 수있는 사소한주의 사항이 있음)을 알려줍니다. 내가 뭘 놓치고 있니?

다음은 코드의 요점 : 그것은 가치가 무엇인지에 대한

if (!window.navigator.standalone) { 
    // show Safari content 
    if (localStorage.name != void 0 && localStorage.var2 != void 0) { 
     // show normal, "add this to your home screen" language - 
     // this screen shows properly 
    } else { 
     // show "We weren't passed our variables" language 
    } 
} else { 
    // Show standalone/offline content 
    if (localStorage.name != void 0 && localStorage.var2 != void 0) { 
     // Show normal standalone app content using localStorage variables. 
     // I'm not seeing this. 
    } else { 
     // Show "error" text, which is what I'm getting 
     document.body.removeChild(document.getElementById('container')); 
     var helper = document.createElement('section') 
      helper.id="helper" 
     helper.innerHTML = '<h1>Sorry</h1>' 
      + '<p>There seems to be a problem with the app.</p>' 
      + '<pre>' 
      + " Name: " + localStorage.name + "\n" 
      + " var2: " + localStorage.var21 + "\n" 
      + '</pre>'; 
     document.body.insertBefore(helper,document.body.firstChild) 
    } 
} 

, 나는 아이폰 OS 6.1에있어. 그래서 그것은 "오래된"문제가되어서는 안됩니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

아직 본 적이 없다면 [이 답변] (http://stackoverflow.com/a/12123291/1947535)이 적합 할 수 있습니다. 특히 Safari의 localStorage가 디스크에 기록한다는 사실은 비동기입니다. –

+0

나는 실제로 가지고 있었지만 그 아래의 주석을 보지 못했다. 불행히도 내가 알 필요가있는 모든 것을 말해 준다. –

답변

0

점 표기법이있는 키에 localStorage 참조를 사용하지 않았습니다. 그러나 localStorage.setItem ("key", value) 및 localStorage.getItem ("key") 메서드는 작동합니다.