【问题标题】:Cordova Camera object emptyCordova 相机对象为空
【发布时间】:2015-02-02 21:15:48
【问题描述】:

我可以使用cordova-plugin-camera 的相机插件从我的移动设备拍照,但在指定相机选项时遇到问题。

我在控制器中尝试了以下操作,以查看 Camera 对象具有哪些键:

$ionicPlatform.ready(function() {
    for (var key in Camera) {
        alert(key);
    }
});

它只返回 getPicture() 方法。缺少其他键,例如“EncodingType”或“MediaType”。当它填充cameraExport对象并且一切都被正确填充(EncodingType等都可用)时,我去并将日志放入相机库中的Camera.js。当它到达我的控制器时它不可用。

当我尝试引用 Camera.EncodingType.JPEG - 我得到“无法读取未定义的属性 JPEG。”

我已经尝试卸载插件并通过 git url 重新安装它,还尝试了 org.apache.cordova.camera 方法(卸载后)。我更新了离子库。创建了新项目,希望这只是一个配置错误。

这是我放在一起的一个示例控制器,它也有问题:

.controller('PhotoCtrl', function($scope, $state, $ionicPlatform, Camera) {
    $ionicPlatform.ready(function() {
        alert(JSON.stringify(Camera)); // This just shows empty brackets: {}
    });

    $scope.getPhoto = function() {
        try {
            // Errors with this alert - if I take it out, it will allow me to take a picture
            alert(Camera.EncodingType.JPEG); 
            Camera.getPicture().then(function(photoUri) {
                alert(photoUri);
            }, function(err) {
                console.err(err);
            },
            {
                // Again, if I remove the Camera.EncodingType.JPEG, it will save the picture
                encodingType: Camera.EncodingType.JPEG,
                // These don't work either. Almost like the options aren't being applied.
                correctOrientation: true,
                saveToPhotoAlbum: true
            });
        }
        catch(err) {
            // Throws the "Cannot read property JPEG of undefined."
            alert(err);
        }
    };
})

有什么想法吗?

如果我可以提供更多信息,请告诉我。

提前致谢!

【问题讨论】:

    标签: cordova camera ionic-framework


    【解决方案1】:

    原来我的相机对象是工厂制造的对象。我只是忘了添加来自 navigator.camera 的常量。

    哇!

    .factory('Camera', ['$q', function($q) {
        return {
            getPicture: function(options) {
                var q = $q.defer();
                navigator.camera.getPicture(function(result) {
                    // Do any magic you need
                    q.resolve(result);
                }, function(err) {
                    q.reject(err);
                }, options);
                return q.promise;
            },
            // Forgot the following
            EncodingType: navigator.camera.EncodingType,
            DestinationType: navigator.camera.DestinationType,
            MediaType: navigator.camera.MediaType,
            PictureSourceType: navigator.camera.PictureSourceType,
            PopoverArrowDirection: navigator.camera.PopoverArrowDirection,
            Direction: navigator.camera.Direction
        }
    }])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多