简体   繁体   中英

Can't use navigator.camera.getPicture on iOS phonegap adobe build

I have been looking for hours now and can't get my phonegap app (compiled by adobe phonegap build) and I fear I am missing something about phonegap. I have added the following lines to the config.xml file:

<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="Camera">
    <param name="ios-package" value="CDVCamera" />
</feature>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/camera"/>

I try to take the picture using the following code:

navigator.camera.getPicture(function(image) {callback("data:image/jpeg;base64," + image)}, cameraFail, { quality: 49 }); 

I am testing it by running it on an iPad2 running iOS 7. I've created a rudimentary inapp console and the problem appears to be that navigator.camera does not exist. Thanks for reading hope you can help.

With help from another answer it lead me to realize what I had done wrong so i'll post for anyone else that is in the same boat.

I hadn't included a reference to cordova.js which should be done just by adding a normal script tag like this:

<script src="cordova.js"></script>

I hadn't included it as I did not have the file cordova.js. What I did not realize is when using the adobe Phonegap Build service the file is added automatically and I did not need it in my source directory, just to include the tag.

Installing plugins for PhoneGap can be difficult.

Do you have the following functions in your code?

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
    destinationType: Camera.DestinationType.DATA_URL
 }); 

function onSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

Your config.xml seems ok.

Also, check the following links:

https://build.phonegap.com/plugins/242

https://github.com/apache/cordova-plugin-camera/tree/fed4f2280d786cabb24641eb6ce686acf98d0a94 (Contains test folder so you can test it on your device)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM