0

我在 iOS 上使用 phonegap 2.0.0 并且基本上使用股票图像捕获代码。捕获图像后将其保存到手机中,URI 与其他项目信息一起保存到数据库中,并且图像显示在页面上。

所有这些都适用于 iOS 和 android。问题是当 iOS 手机关闭并允许坐一段时间(过夜)时,图像不再显示。其余数据从数据库中检索并显示,但图像仅显示图像应位于的黑色方块(表明信息仍在数据库中)

iOS 是否会在关闭并允许静置一段时间后重命名图像?有什么建议么?如果手机关闭并重新打开,这不会发生......只有在手机放置一段时间后......

这似乎非常相关... 捕获用相机拍摄的照片并将其存储到本地数据库/PhoneGap/Cordova/iOS

4

1 回答 1

0

对于遇到此问题的其他人,以下代码对我有用...

    function capturePhoto() {
navigator.camera.getPicture(movePic, onFail,{ quality : 70 });
}

function movePic(file){ 
window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError); 
} 

function resolveOnSuccess(entry){ 
var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";
var myFolderApp = "myPhotos";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {      
fileSys.root.getDirectory( myFolderApp,
                {create:true, exclusive: false},
                function(directory) {
                    entry.moveTo(directory, newFileName,  successMove, resOnError);
                },
                resOnError);
                },
resOnError);
}
function successMove(imageUri) {
    document.getElementById('smallImage').src = imageUri.fullPath;
    //hidden input used to save the file path to the database
    document.getElementById('site_front_pic').value = "file://"+imageUri.fullPath;
    smallImage.style.display = 'block';
}

function onFail(message) {
alert('Failed to load picture because: ' + message);
}

function resOnError(error) {
alert(error.code);
}
于 2013-05-20T03:26:12.953 回答