(IOS)Cordova相机插件引用被删除的图像 [英] (IOS) Cordova Camera Plugin Referring to deleted images

查看:203
本文介绍了(IOS)Cordova相机插件引用被删除的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个cordova应用程式(主要用于iOS和Android),其中使用者可以拍摄图片,重新拍摄(等等)并储存在本机中。

I'm building a cordova app (primarily for IOS & Android) in which the user can take an image, retake (, etc.) it and save it locally.

我目前正在使用cordova cameraPlugin。所以,这里是对问题的简短描述。

I'm currently struggling with the cordova cameraPlugin. So, here a short description of the problem.

当用户拍摄图像时,它保存在本地的apps临时文件夹,用户能够在UIWebView。重新获取时,映像将从临时文件夹中删除,不应再存在(在RAM和本地FS中)。
只要用户不重新拍摄图片2次或更多次,它就可以工作,如果他不是最后一个图片,那么第一个图片将在WebView中被引用/渲染。重新打开应用后,图片会正确显示。

When the user takes an image, it's saved locally in the apps temp folder and the user is able to view in in the UIWebView. On retaking, the image will be deleted from the temp folder and should not be available any longer (in RAM and local FS). It works as long as the user doesn't retakes the image 2 or more times, if he does instead of the last image the first image will be referenced/rendered in WebView. After reopening the app, the image is displayed correctly.

例如:


  1. 用户拍摄第一张图像。 ==> cdv_photo_001.png

  2. 第二个。 ==> cdv_photo_002.png,第一个将被删除(似乎工作正常)

  3. 第三个。 ==> cdv_photo_001.png,第二张图片将被删除。

第三张图片看起来与 deleted 第一个。这发生在第三个图像之后的每个图像。
重新启动应用后可正常工作

The third image will look the same as the deleted first one. This happens with every image after the third one. It works fine after restarting the app

我已经尝试禁用App-Cache,更新图片,刷新页面并在线寻找答案。

I've already tried to disable the App-Cache, delete the app cache before updating the image, refreshing the page and looking for answers online.

打开相机UI时出现错误,但我找不到解决方案。

I'm getting an error when opening the camera UI, but I could not find a solution for it either.


快照未呈现的视图会导致空快照。确保您的视图至少在
快照或屏幕更新后的快照中已呈现一次。

for the camera Call:

The code for the camera Call:

function getPhoto() {
    navigator.camera.getPicture(getPhotoOnSuccess, getPhotoOnFail, {
        quality: 25,
        destinationType: Camera.DestinationType.FILE_URL,
        correctOrientation: true,
        encodingType: Camera.EncodingType.PNG
    });
}

在getPhotoOnSuccess中,我基本上将图像路径保存到数据库,

In getPhotoOnSuccess I'm basically saving the image path to a db and appending it with jQuery to the view.

和删除图像的代码:(sidenote我对Objective C是新的)

And the code to delete the image: (sidenote I`m new to Objective C)

- (void) deleteImageByPath:(NSString *)imagePath withSelector:(SEL)selector{
    NSError *error = nil;
    NSFileManager *mgr = [NSFileManager defaultManager];
    NSString *tempFolder = NSTemporaryDirectory();

    if([mgr removeItemAtPath: imagePath error:&error] == NO) {
        NSLog(@"File deleted");
    }

    //The files can be edited as well, so there can be two files in different directories
    if(error != nil){    
        NSString *imgEl = tempFolder;
        imgEl = [imgEl stringByAppendingPathComponent:imagePath.lastPathComponent];
        if(![mgr removeItemAtPath:imgEl error:&error]){
            NSLog(@"Old element couln't be deleted.");
        }
    }

    [self performSelector:selector withObject:error];
}

删除后该文件不在目录中,所以我想作品。
一个重要的细节可能是,我写了我自己的IOS cordova插件,因为文件系统访问提供的方法cordova吸。

The file is not in the directory anymore after deleting it, so I guess it works. An important detail could be, that I wrote my own IOS cordova plugin, because the method for the file system access provided by cordova sucks.

就是这样。
具体问题是:为什么,如何发生,是否有机会改变这种行为?如果是的话,我该怎么办?

So thats it. The specific question is: Why and how is this happening and is there a chance to change this behavior? If yes, how should I proceed?

顺便说一句,我使用cordova 3.1.0,构建目标是IOS 7.

By the way, I`m using cordova 3.1.0 and the build target is IOS 7.

提前感谢。

推荐答案

好的,我终于得到了。

整个问题与我的代码或任何cordova代码无关。
那么为什么会发生呢? ==>我不完全知道,因为似乎这个错误或任何你可能称为它,发生在许多人。

The whole problem was not related to my code or any of the cordova code. So why did it happen? ==> I don't exactly know that, for it seems that this bug or whatever you might call it, has occurred to many people.

他们都试图删除或停用缓存,就像我一样,他们的一些问题非常接近我自己,但大多数不是,所以花了一会儿,直到我找到一个解决方案。

And they all tried to delete or deactivate the cache as I did, some of their problems are very close to my own but most aren't, so it took a while til I found a solution.

我阅读了此主题,并尝试将时间戳附加到图像路径和它工作!
我的结论,这可能是UIWebView和缓存管理的一个问题。

或者它可能证明作为一个一般的WebView问题,我将能够检查在一个几天在Adroid设备上。

I read this thread and tried to append a timestamp to the image path and it worked! My conclusion to this it, that there might be a problem with the UIWebView and the cache management.
Or it might proof as a general WebView problem, I will be able to check that in a few days on an Adroid device.

这篇关于(IOS)Cordova相机插件引用被删除的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆