无法加载资源:不支持的网址

时间:2017-05-10 00:50:50

标签: ios xcode cordova backbone.js camera

我的代码在以下行中抛出此错误Failed to load resource: unsupported url

self.$el.find('.capturedImage').attr('src', imageData);

这是imageData

的值
assets-library://asset/asset.JPG?id=106E99A1-4F6A-45A2-B320-B0AD4A8E8473&ext=JPG

使用插件cordova-plugin-camera 2.4.1 "Camera"在iPhone模拟器上运行cordova应用程序时会发生这种情况.Xcode中的部署目标设置为9.0

render: function (context, template) {
        var self = this;
        View.__super__.render.apply(this, [context, template]);
        setTimeout(function() {
            var imageData = app.selectedYoungPerson.imageData;
            if (app.selectedYoungPerson.fromCamera) {
                if (imageData.indexOf('data:image/jpeg;base64,') != 0 && imageData.indexOf('data:;base64,') != 0) {
                    self.$el.find('.capturedImage').attr('src', "data:image/jpeg;base64," + imageData);
                }
            }else{
                    self.$el.find('.capturedImage').attr('src', imageData);
            }
            self.startCrop.apply(self,[]);
        }, 1000);

getBrowseImage: function(data) {
        var self = this;
        var destinationType = (navigator.userAgent.match(/iemobile/i)) ? navigator.camera.DestinationType.DATA_URL : navigator.camera.DestinationType.NATIVE_URI;
        navigator.camera.getPicture(function(imgData) {
                var fileName = 'img_'+(new Date()).valueOf()+'.jpg';
                if(data.callback) {
                    data.imgData = imgData;
                    data.fileName = fileName;
                    data.fromCamera = false;
                    data.callback.apply(data.ref, [data]);
                    //self.uploadImage(data);
                }
            }, function(err) {
                alert('Image cpature failed : '+err);
            }, {
                quality: 100,
                allowEdit: true,
                correctOrientation: true,
                destinationType: destinationType,
                sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
            }
        );
    },

这是我的插件列表:

cordova-plugin-camera 2.4.1" Camera"

cordova-plugin-compat 1.1.0" Compat"

cordova-plugin-file 4.3.2" File"

cordova-plugin-file-transfer 1.6.2"文件传输"

cordova-plugin-whitelist 1.3.2" Whitelist"

org.apache.cordova.console 0.2.11" Console"

1 个答案:

答案 0 :(得分:2)

navigator.camera.DestinationType.NATIVE_URI;替换为navigator.camera.DestinationType.FILE_URI

,解决了这个问题