简体   繁体   中英

iOS PhoneGap camera can't save image to Photo Library

I'm sort of stuck with phonegap-iOS problem and I hope someone can help me.

I created a simple app using PhoneGap 1.0. I'd like to take a picture and the save it to photo library. I've read the PhoneGap API documentation. Here is my code.

function getImage() {
    navigator.camera.getPicture(onSuccess,
        onFail,
        { 
            quality: 20, 
            destinationType: navigator.camera.DestinationType.FILE_URI,
            saveToPhotoAlbum: true
        });
}

function onSuccess(imageURI) {
    alert("Image taken");
}

function onFail(error) {
    alert("Fail when getting image. Code = " = error.code);
}

With that code, I'm able to take a photo using device camera but the photo won't save in picture library. I'm using XCode 4.0.1, device I use to test this code is iPad2 (iOS 4.3.5) and iPhone 3GS (iOS 4.2.1).

Can anyone help me here, please?

Thanks in advance.

I have solved this problem. Instead of using getPicture() , I used captureImage() .

Below is the code I used:

function getImage() {
    navigator.device.capture.captureImage(onSuccess,
        onFail,
        { 
             limit: 1
        });
}

function onSuccess(imageURI) {
    alert("Image taken");
}

function onFail(error) {
    alert("Fail when getting image. Code = " = error.code);
}

With this code, I'm able to trigger camera to get a photo, and the photo take is saved to photo library of iPad (I only tested this on iPad2 iOS 4.3.5, haven't tested it on iPhone yet).

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