【问题标题】:Cordova Camera plugin gives error 'object' has no method "getPicture"Cordova 相机插件给出错误“对象”没有方法“getPicture”
【发布时间】:2018-06-22 18:03:46
【问题描述】:

在正确设置所有内容(如之前多次完成)后,我正在开发 ionic v1 Camera 应用程序。在构建应用程序并对其进行调试后,我得到了这个错误。

插件安装正确, ng-cordova.min 包括在内。 $CordovaCamera 注入。 这是我的代码:

$scope.takePhoto = function () {
              var options = {
                quality: 100,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: true,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 300,
                targetHeight: 300,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: true
            };

                $cordovaCamera.getPicture(options).then(function (imageData) {
                    $rootScope.imgURI = "data:image/jpeg;base64," + imageData;
                    $state.go('menu.signUp');
                }, function (err) {
                    // An error occured. Show a message to the user
                });
            }

功能运行良好。但相机没有打开并给出错误 如图所示。

【问题讨论】:

    标签: android angularjs cordova ionic-framework camera


    【解决方案1】:

    尝试在接触控制器中注入 $cordovaCamera 并像这样使用它

    camera.getPicture() //只是相机而不是 $cordovaCamera

    【讨论】:

      【解决方案2】:

      使用 camera.getPicture() 或 navigator.camera.getPicture()

      https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/

      【讨论】:

        【解决方案3】:

        确保 $cordovaCamera 依赖注入然后像这样使用它

        $cordovaCamera.getPicture(options).then(function(imageData) {
          var image = document.getElementById('myImage');
          image.src = "data:image/jpeg;base64," + imageData;
        }, function(err) {
          // error
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-09-18
          • 1970-01-01
          • 2015-01-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-17
          • 1970-01-01
          相关资源
          最近更新 更多