최근에 사진을 저장하려고 할 때 Ionic 응용 프로그램에 문제가 발생했습니다.
이미지를 캡처하고 내 범위에 base64 문자열로 저장하기 위해 ngcordova 플러그인을 사용하고 있습니다.
나는 사진을 저장하기 위해 localstorage를 사용하기로 결정했습니다. 그다지 중요하지 않은 이미지 품질이 낮기 때문입니다.
사진을 찍는 방법
$scope.takePictureFront = function(){
var cameraOptions = {
quality: 10,
destinationType: Camera.DestinationType.DATA_URL
};
var success = function(data){
$scope.$apply(function () {
/*
remember to set the image ng-src in $apply,
i tried to set it from outside and it doesn't work.
*/
$scope.cameraPicFront = "data:image/jpeg;base64," + data;
alert('Inserting front ');
});
};
var failure = function(message){
alert('Failed because: ' + message);
};
//call the cordova camera plugin to open the device's camera
navigator.camera.getPicture( success , failure , cameraOptions );
};
localstorage에 저장할 개체
var newCustomer = {
firstname: $scope.customer.firstname(),
lastname: $scope.customer.lastname(),
title: $scope.customer.title(),
phone: $scope.customer.phone(),
cellphone: $scope.customer.cellphone(),
email: $scope.customer.email(),
timeStamp: today,
metAt: $scope.conferencePicked,
addedBy : $scope.userLoggedIn,
imageFront : $scope.cameraPicFront,
imageBack : $scope.cameraPicBack,
comment: $scope.customer.comment(),
interests : $scope.selected
};
객체 배열이 localstorage에 저장되는 방법
$scope.storedJSON = JSON.parse(window.localStorage['data'] || '{"companies":[],"customers":[]}');
$scope.storedJSON.customers.push(newCustomer);
$scope.storedJSON.companies.push(newCompany);
var jsonData = JSON.stringify($scope.storedJSON);
window.localStorage['data'] = jsonData;
$state.go('tab.search');
ipad, 태블릿 및 Android 장치에서 날짜를 입력하려고 할 때 앱이 유휴 상태가 된 다음 충돌하거나 응답하지 않습니다.
어떤 권장 사항이 있습니까?
편집하다
이에 대한 해결 방법을 찾았습니다. 내가 이것을 시도한 훌륭한 전화와 태블릿조차도 그러한 파일을 localstorage에 저장하는 데 문제가 있습니다.
나는 카메라 플러그인의 옵션을 편집했고 이제 더 낮은 taget 해상도로 더 작은 이미지를 저장하고 있으며 모든 것이 잘 작동하는 것 같습니다. 미래에이 버려진 질문에 걸려 넘어지는 사람을 위해 :)
응용 프로그램에 메모리 누수가있을 수 있습니다. 귀하의 앱이 어떻게 작동하는지 모르기 때문에 이것이 최선의 추측입니다. 시도 할 수있는 또 다른 방법은 LocalStorage가 허용되는지 확인하는 것입니다. LocalStorage (개인 경험)를 사용하려고 할 때 많은 메모리 위반이있었습니다.
내가 추천 할 수있는 것은 base64를 텍스트 파일에 저장하는 것입니다. 이것은 읽기 / 쓰기 작업이 실제로 메모리를 적게 사용하므로 응용 프로그램의 성능을 방해하지 않습니다. :)
보세요 :
$scope.saveFileToDataStorate = function() {
var data = JSON.stringify( newCustomer );
$cordovaFile.writeFile( cordova.file.dataDirectory, 'userDetails.txt', data )
.then( function( suc ){
alert( 'File Saved! You can now try and open it.' );
}, function( error ){ alert( error.code ); });
};
$cordovaFile
컨트롤러에 종속성 을 포함해야합니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다