2016-10-25 11 views
0

私はイオンフレームを使用します。コンパイル後にカメラが機能しない

カメラは完全にで動作します。Ionic Viewしかし、iOS上での動作後は動作しません。

問題の原因を調べてください。 services.js

カメラコード:

app.factory('FileService', function() { 
    var images; 
    var IMAGE_STORAGE_KEY = 'dav-images'; 

    function getImages() { 
    var img = window.localStorage.getItem(IMAGE_STORAGE_KEY); 
    if (img) { 
     images = JSON.parse(img); 
    } else { 
     images = []; 
    } 
    return images; 
    }; 

    function addImage(img) { 
    images.push(img); 
    window.localStorage.setItem(IMAGE_STORAGE_KEY, JSON.stringify(images)); 
    }; 

    return { 
    storeImage: addImage, 
    images: getImages 
    } 
}); 

app.factory('ImageService', function($cordovaCamera, FileService, $q, $cordovaFile) { 

    function optionsForType(type) { 
    var source; 
    switch (type) { 
     case 0: 
     source = Camera.PictureSourceType.CAMERA; 
     break; 
     case 1: 
     source = Camera.PictureSourceType.PHOTOLIBRARY; 
     break; 
    } 
    return { 
     quality: 90, 
     destinationType: Camera.DestinationType.DATA_URL, 
     sourceType: source, 
     allowEdit: false, 
     encodingType: Camera.EncodingType.JPEG, 
     popoverOptions: CameraPopoverOptions, 
     saveToPhotoAlbum: false, 
     correctOrientation:true 
    }; 
    } 

    function saveMedia(type) { 
    return $q(function(resolve, reject) { 
     var options = optionsForType(type); 

     $cordovaCamera.getPicture(options).then(function(imageBase64) { 
     FileService.storeImage(imageBase64); 
     }); 
    }) 
    } 
    return { 
    handleMediaDialog: saveMedia 
    } 
}); 

カメラコードcontrollers.js中:

app.controller('CameraController', function($scope, $cordovaDevice, $cordovaFile, $ionicPlatform, $cordovaEmailComposer, $ionicActionSheet, ImageService, FileService) { 

    $ionicPlatform.ready(function() { 
    $scope.images = FileService.images(); 
    $scope.$apply(); 
    }); 

    $scope.addMedia = function() { 
    $scope.hideSheet = $ionicActionSheet.show({ 
     buttons: [ 
     { text: 'Take photo' }, 
     { text: 'Photo from library' } 
     ], 
     titleText: 'Add images', 
     cancelText: 'Cancel', 
     buttonClicked: function(index) { 
     $scope.addImage(index); 
     } 
    }); 
    } 

    $scope.addImage = function(type) { 
    $scope.hideSheet(); 
    ImageService.handleMediaDialog(type).then(function() { 
     $scope.$apply(); 
    }); 
    } 

    $scope.sendEmail = function() { 
    if ($scope.images != null && $scope.images.length > 0) { 
     var mailImages = []; 
     var savedImages = $scope.images; 
     for (var i = 0; i < savedImages.length; i++) { 
     mailImages.push('base64:attachment'+i+'.jpg//' + savedImages[i]); 
     } 
     $scope.openMailComposer(mailImages); 
    } 
    } 

    $scope.openMailComposer = function(attachments) { 
    var bodyText = '<html><h2>My Images</h2></html>'; 
    var email = { 
     to: '', 
     attachments: attachments, 
     subject: 'Devdactic Images', 
     body: bodyText, 
     isHtml: true 
    }; 

    $cordovaEmailComposer.open(email, function(){ 
     console.log('email view dismissed'); 
    }, this); 
    } 
}); 
+1

あなたが言っていることによると、私はあなたがすることを忘れてしまったと信じています: 'cordova plugin add cordova-plugin-camera'。これが機能しない場合は、コードを投稿して、実際には動作しないことを教えてください。 – e666

+0

cordova plugin add cordova-plugin-cameraが追加されました。コードのリンクは次のとおりです。https://github.com/vitaly-safonov/Hair-plus –

+0

あなたの問題をさらに記述してください。あなたが受け取ったエラーは何ですか?あなたはサファリコンソールを見ようとしましたか?また、あなたのコードについては、[最小限で完全で検証可能なサンプルの作成方法](http://stackoverflow.com/help/mcve)をご覧ください。私たちはあなたのコードをすべて読んで、カメラをどこで使うのか探しません。 – e666

答えて

0

あなたはXCodeのでアプリをコンパイルする必要があり、この問題を解決するには。 の後Xcodeコンパイルカメラが正しく動作します。

おそらく、カメラの問題は、Ionicが原因です。

関連する問題