2017-09-12 1 views
0

내 앱에 미치광이가납니다.DevExtreme/Phonegap 카메라 플러그인 : "정의되지 않은 propetry 'getPicture'를 읽을 수 없습니다."

나는 PhoneGap을 기반으로하는 DevExtreme을 사용하고 있습니다.

내 앱에서 카메라로 사진을 찍고 싶지만 몇 가지 문제가 있습니다.

우선 여기 내 config.xml입니다.

<widget id="com.devexpress.apptemplate" version="1.0" versionCode="1"> 
    <name>ApplicationTemplate</name> 
    <description>Template</description> 
    <preference name="permissions" value="none" /> 
    <preference name="prerendered-icon" value="true" /> 
    <preference name="android-windowSoftInputMode" value="adjustPan" /> 
    <preference name="SplashScreenDelay" value="60000" /> 
    <preference name="AutoHideSplashScreen" value="false" /> 
    <preference name="SplashShowOnlyFirstTime" value="false" /> 
    <preference name="FadeSplashScreen" value="false" /> 
    <preference name="ShowSplashScreenSpinner" value="false" /> 
    <preference name="DisallowOverscroll" value="true" /> 
    <preference name="StatusBarOverlaysWebView" value="false" /> 
    <preference name="StatusBarBackgroundColor" value="#000000" /> 
    <preference name="android-minSdkVersion" value="14" /> 
    <preference name="android-targetSdkVersion" value="22" /> 
    <plugin name="cordova-plugin-camera" spec="^2.4.1" source="npm" /> 
    <plugin name="cordova-plugin-splashscreen" onload="true" /> 
    <plugin name="cordova-plugin-whitelist" /> 
    <plugin name="cordova-plugin-ios-longpress-fix" /> 
    <plugin name="cordova-plugin-statusbar" onload="true" /> 
    <access origin="*" /> 
</widget> 

여기에 잘못된 것이 있습니까? 여기

// Called when a photo is successfully retrieved 
// 
function onPhotoDataSuccess(imageData) { 
    try 
    { 
     // Get image handle 
     // 
     var smallImage = document.getElementById('smallImage'); 
     // Unhide image elements 
     // 
     smallImage.style.display = 'block'; 
     // Show the captured photo 
     // The inline CSS rules are used to resize the image 
     // 
     smallImage.src = "data:image/jpeg;base64," + imageData; 
    } 
    catch (err) { 
     alert(err.message); 
    } 
} 

// Called when a photo is successfully retrieved 
// 
function onPhotoFileSuccess(imageData) { 
    // Get image handle 
    console.log(JSON.stringify(imageData)); 

    // Get image handle 
    // 
    var smallImage = document.getElementById('smallImage'); 
    // Unhide image elements 
    // 
    smallImage.style.display = 'block'; 
    // Show the captured photo 
    // The inline CSS rules are used to resize the image 
    // 
    smallImage.src = imageData; 
} 
// Called when a photo is successfully retrieved 
// 
function onPhotoURISuccess(imageURI) { 
    // Uncomment to view the image file URI 
    // console.log(imageURI); 
    // Get image handle 
    // 
    var largeImage = document.getElementById('largeImage'); 
    // Unhide image elements 
    // 
    largeImage.style.display = 'block'; 
    // Show the captured photo 
    // The inline CSS rules are used to resize the image 
    // 
    largeImage.src = imageURI; 
} 
// A button will call this function 
// 
function capturePhotoWithData() { 
    try { 
     // Take picture using device camera and retrieve image as base64-encoded string 
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 }); 
    } 
    catch (err) { 
     alert(err.message); 
    } 
} 
function capturePhotoWithFile() { 
    navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); 
} 

// A button will call this function 
// 
function getPhoto(source) { 
    debugger; 
    // Retrieve image file location from specified source 
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { 
     quality: 50, 
     destinationType: OverviewAPP.destinationType.FILE_URI, 
     sourceType: source 
    }); 
} 
// Called if something bad happens. 
// 
function onFail(message) { 
    alert('Failed because: ' + message); 
} 

그리고 내 관련 HTML은 : : 또한

, 나는 (튜토리얼에서 복사) 카메라 함수를 호출 할 수있는 버튼이

[...] 
<div class="myBtnPhoto" data-bind="dxButton: { text: 'Conferma con foto', onClick: capturePhotoWithData}" style="float:right;"></div> 
[...] 
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" /> 
<img style="display:none;" id="largeImage" src="" /> 
[...] 

함수 capturePhotoWithData가 제대로 호출을하지만, 함수는 catch 브랜치에 들어가고 경고는 "정의되지 않은 propetry 'getPicture'를 읽을 수 없음을 보여줍니다.

템플릿을 만들고 해결책을 만듭니다. 내 안드로이드 장치에서 이것을 시도하고 있습니다. 나는 웹에서 많은 포럼과 다른 질문을 읽었지 만, 여전히 나를 위해 일한 것은 아무것도 없다.

여기에 실수 나 실수가 있습니까?

답변

0

즉, navigator.camera은 정의되지 않았으므로 프로젝트에 cordova-plugin-camera이 표시되지 않습니다.

가장 일반적인 문제는 기기를 준비하기 전에 호출하는 것입니다. 당신이 deviceready에 카메라를 호출 있는지 확인 : 당신은 실행할 수 있습니다

document.addEventListener("deviceready", function(){ 
    console.log(navigator); // here you can check all plugins 
} 

: $ cordova plugin list을이 플러그인은 또한 목록에 있는지 확인하기 위해. 나는 이미 그것을 두려워

+0

확인 $ cordova build android (또는 iOS)을하지만, 왜 정의되지 않은 :

또한 다시 시도? 나는 미쳐 버렸고 다른 앱 (예 : 푸시 알림)의 다른 플러그인을 관리했지만이 경우에는 막혔습니다. 코드바를 실행할 수 없습니다 (또는 DevExtreme 프로젝트에서 코드바를 수행하는 방법을 모르겠습니다). 어쨌든 이상한 점은 apk 플러그인 폴더에서 볼 수 있지만 설치하면 앱에 데이터 저장 권한 만 있고 카메라 권한은 필요하지 않습니다. –

+0

장치를 준비하기 전에 어떻게 호출 할 수 있습니까? 응용 프로그램이 시작된 후 로그인하고 오른쪽 섹션으로 이동해야하므로 가능하지 않다고 생각하니? –

+0

@PieroAlberto 방금 문제가있는 곳을 감지 할 수있는 도구를 제공합니다. –

관련 문제