Programing

Android 및 iOS의 로컬 저장소는 얼마나 영구적입니까?

lottogame 2020. 10. 22. 07:39
반응형

Android 및 iOS의 로컬 저장소는 얼마나 영구적입니까?


내 앱이 휴대 전화에 로컬로 데이터를 저장할 때 해당 저장소는 얼마나 영구적입니까? 정확한 상황을 자세히 설명하겠습니다.

jQueryMobile과 Phonegap으로 앱을 만들고 있습니다. 본질적으로 브라우저 앱이지만 Phonegap을 사용하면 다른 장점 중에서도 패키징하여 앱 스토어에서 판매 할 수 있습니다.

Phonegap은 두 가지 저장 방법을 제공하는데, 두 기능 모두 iOS, Android, Blackberry 및 일부 다른 OS의 기본 기능을 조화시킵니다. localStorage (기본 키-값 쌍) 및 웹 SQL 데이터베이스. localStorage와 웹 SQL은 모두 브라우저에 속하는 스토리지 형식입니다. 그러나 데이터가 얼마나 오래 저장되는지, 어떤 상황에서 삭제 될지, 어떤 상황에서 사용할 수 없는지 등을 알 수 없습니다.

예를 들어 앱이 localStorage 또는 웹 SQL을 사용하여 데이터를 저장하고 사용자가 Android에서 다른 표준 브라우저로 전환하는 경우 앱이 새 브라우저로 열리 며 저장된 데이터를 사용할 수 없음을 의미합니까?

사용자가 1 년 동안 앱을 사용하지 않는 경우 (제 경우에는 현실적이고 나쁜 시나리오는 아닙니다) 데이터가 쿠키처럼 만료되었거나 브라우저의 저장 공간에서 다른 앱의 데이터?

또는 다음과 같은 경우에 데이터가 더 일찍 파기됩니다.-사용자가 브라우저에서 다른 사이트를 방문-브라우저가 수동으로 닫힘-브라우저 프로세스가 종료되거나 죽는 경우-등

아니면 localStorage 및 웹 SQL이 Android에서 설정> 앱으로 이동하여 앱과 관련된 사용자 데이터를 적극적으로 제거 할 때만 삭제하는 저장소 유형입니까?

통찰력을 가져 주셔서 감사합니다. 이전 WWW에는 유익한 정보가 없습니다.

앱 업데이트의 경우 어떻게 되나요? 로컬 및 웹 저장소가 삭제되거나 유지됩니까?


단계적으로 대답하겠습니다

앱이 localStorage 또는 웹 SQL을 사용하여 데이터를 저장하고 사용자가 Android에서 다른 표준 브라우저로 전환하는 경우 앱이 새 브라우저로 열리 며 저장된 데이터를 사용할 수 없음을 의미합니까?

데이터는 브라우저의 '캐시'(정확히 캐시가 아님)에 저장되므로 브라우저를 변경하거나 기본 브라우저를 제거하거나 변경하도록 설정하면 데이터가 이동합니다.

사용자가 1 년 동안 앱을 사용하지 않는 경우 (제 경우에는 현실적이고 나쁜 시나리오는 아닙니다) 데이터가 쿠키처럼 만료되었거나 브라우저의 저장 공간에서 다른 앱의 데이터?

아니요, 데이터는 얼마나 오래 사용되지 않더라도 그대로 유지됩니다. 따라서 브라우저 캐시를 지우더라도 여전히 거기에 있습니다.

또는 다음과 같은 경우에 데이터가 더 일찍 파기됩니다.-사용자가 브라우저에서 다른 사이트를 방문-브라우저가 수동으로 닫힘-브라우저 프로세스가 종료되거나 죽는 경우-등

아니요, 데이터는 정상적으로 유지됩니다. :-)

아니면 localStorage 및 웹 SQL이 Android에서 설정> 앱으로 이동하여 앱과 관련된 사용자 데이터를 적극적으로 제거 할 때만 삭제하는 저장소 유형입니까?

예, 데이터는 앱에서 수동으로 삭제하거나 앱을 제거한 경우에만 저장됩니다. 다른 모든 경우에는 그대로 유지됩니다.

편집 : iOS의 경우 장치에 메모리가 부족하면 OS가 로컬 저장소의 데이터를 제거합니다.


iOS 5.1부터 @ghostCoder의 답변은 더 이상 유효하지 않습니다. Apple은 localstorage 위치를 언제든지 비울 수있는 캐시 폴더로 이동하기로 결정했습니다. 여기에서이 토론을 추적 할 수 있습니다.

Localstorage에 대한 Google 그룹스 토론

또한이 블로그에서는 문제에 대해 자세히 설명합니다.

http://www.marco.org/2011/10/13/ios5-caches-cleaning

localstorage 위치를 안전한 Application_Home> / Documents 위치 로 수동으로 지정할 수 있습니다 . 현재 localstorage 위치를 확인하려면 다음과 같이 사용할 수 있습니다.

NSString* localStorageSubdir = (IsAtLeastiOSVersion(@"5.1")) ? @"Caches" : @"WebKit/LocalStorage";
NSString* localStoragePath = [library stringByAppendingPathComponent:localStorageSubdir];
NSString* localStorageDb = [localStoragePath stringByAppendingPathComponent:@"file__0.localstorage"];

다음 코드를 사용하면 localstorage의 다른 위치를 설정할 수 있습니다.

NSString* bundleIdentifier = [[mainBundle infoDictionary] objectForKey:@"CFBundleIdentifier"];
NSString* libraryPreferences = @"Library/Preferences";
NSString* appPlistPath = [[bundlePath stringByAppendingPathComponent:libraryPreferences]    stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist", bundleIdentifier]];

NSString *value;
NSString *key = @"WebKitLocalStorageDatabasePathPreferenceKey";
value = [appPlistDict objectForKey: key];
if (![value isEqual:ourLocalStoragePath]) {
    [appPlistDict setValue:yourPreferredLocalStoragePath forKey:key];
} 

NativeStorage 플러그인을 사용해보십시오. https://www.npmjs.com/package/cordova-plugin-nativestorage .

Android 공유 환경 설정 및 데이터 저장소를 허용되는 한 안전하게 만드는 iOS NSUserDefaults와 같은 플랫폼 기능을 구현하는 기능을 설정, 입력 및 가져옵니다.

cordova plugin add cordova-plugin-nativestorage

NativeStorage.putObject("reference_to_value",<object>, <success-callback>, <error-callback>);

NativeStorage.getObject("reference_to_value",<success-callback>, <error-callback>);

현재 사용 가능한 좋은 솔루션은 The Cordova Native Storage Plugin 입니다.

안정성을 보장하기 위해 Android에서는 SharedPreferences를, iOS에서는 NSDefault를 기본적으로 구현하여 간단하지만 기본 지속성 방법으로 iOS 및 Android에 데이터를 저장할 수 있습니다.

용법:

설치:

cordova plugin add cordova-plugin-nativestorage

값 저장 :

NativeStorage.setItem("reference_to_value",<value>,<success-callback>, <error-callback>);

값 검색 :

NativeStorage.getItem("reference_to_value",<success-callback>, <error-callback>);

에는 안드로이드 가 기본적으로 영구 저장합니다. 사용자가 앱을 업데이트하더라도 동일하게 유지됩니다.

The user can go to settings and clear cache and data in which case it goes or if say one of the clean-it apps does it.

Even on iOS it's permanent storage but don't know about app update scenario. But in older version(5.1) it wasn't and in 6+ they made that it can be made permanent through a flag which was promptly enabled by cordova/phonegap.


I can't speak for other platforms, but on my 4.1 Android device, I'm using localStorage to store some data locally with jQuery Mobile, and I've found that Android will clear my cache every week or so without my knowledge. I'm going to give Web SQL a try and see if that's better.


It would be better in terms of performance, security and reliability to AVOID using local storage and use Cordova-sqlite-storage instead.

Some notes:

localStorage has the advantage of being easy to use, but it works in a synchronous way. This means that it can lock the UI thread and cause slow performance.

localStorage has a limited amount of storage, usually its 5mb.

localStorage can be wiped out by the OS (android,ios) at any time. This is really serious if you care about data persistance.

On the other hand:

Cordova-sqlite-storage is asynchronous and it will not block the UI thread, it saves your data on the native device storage, the amount of storage is not limited, the OS will not delete any of your data, unless you uninstall the app.


I found this online ng-persist

Store data on mobile devices (using cordova) that persists even if the user reinstalls the app

Install

bower install ng-persist ngstorage --save

Inject $persist into your controller

.controller('MyCtrl', function($persist) {

    $persist
        .set(namespace, key, val)
        .then(function () {
            // saved
        });

    // read
    $persist
        .get(namespace, key, fallback)
        .then(function (val) {
            // val is either the value, if exists, or the fallback
        });

    // delete
    $persist
        .remove(namespace, key)
        .then(function () {
            // removed
        });

});

참고URL : https://stackoverflow.com/questions/7750857/how-permanent-is-local-storage-on-android-and-ios

반응형