iOS - Can't get navigator.camera.getPicture to work

2,259 views
Skip to first unread message

ScottP

unread,
Mar 21, 2012, 8:39:37 AM3/21/12
to phonegap
Hey All,
I can't seem to get the camera.getPicture function to work.
I'm using Xcode 4.3.1 on snow leopard.
Phonegap 1.1.0 with JQTouch.
I've tried on actual devices: iPod (4th gen with camera) and iPad2
(with camera).
I don't get any error messages in console or anything.
If I change it to use the capture.captureImage API then the camera
does indeed open and I can save a photo to the camera roll.
But for some reason camera.getPicture is just not working. I'd like to
be able to grab the file URIs from the albums and camera roll.
I added an alert just before navigator.camera.getPicture in the
getPhoto function and it shows up. When I put the alert after it I
get no alert.

I'm using the code straight from http://docs.phonegap.com/en/1.1.0/phonegap_camera_camera.md.html#Camera

Any suggestions on how to go about troubleshooting this?


function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}


function getPhoto(source) {
// Retrieve image file location from specified source

navigator.camera.getPicture(onPhotoURISuccess, onFail,
{ quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}

// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}

function onPhotoURISuccess(imageURI) {
alert(imageURI);
}

And in html:
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo
Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From
Photo Album</button><br>

Thanks,
Scott

ScottP

unread,
Mar 21, 2012, 10:02:17 AM3/21/12
to phonegap
I should have specified both devices are running iOS 5.1

On Mar 21, 8:39 am, ScottP <scott.a.padi...@gmail.com> wrote:
> Hey All,
> I can't seem to get the camera.getPicture function to work.
> I'm using Xcode 4.3.1 on snow leopard.
> Phonegap 1.1.0 with JQTouch.
> I've tried on actual devices: iPod (4th gen with camera) and iPad2
> (with camera).
> I don't get any error messages in console or anything.
> If I change it to use the capture.captureImage API then the camera
> does indeed open and I can save a photo to the camera roll.
> But for some reason camera.getPicture is just not working. I'd like to
> be able to grab the file URIs from the albums and camera roll.
> I added an alert just before navigator.camera.getPicture in the
> getPhoto function and it shows up.  When I put the alert after it I
> get no alert.
>
> I'm using the code straight fromhttp://docs.phonegap.com/en/1.1.0/phonegap_camera_camera.md.html#Camera

Paul D. Clegg

unread,
Mar 23, 2012, 6:16:42 AM3/23/12
to phon...@googlegroups.com
Hi Scott,

I can confirm I am having the same problem with IOS5.1  using PG 1.3.  The feature works in the simulator but no on the phone. I am using the latest version of xcode.

If i find a fix I will update this thread.

zSprawl

unread,
Mar 23, 2012, 5:09:23 PM3/23/12
to phon...@googlegroups.com
My App called Demotivate zApp is using iOS5.1, Cordova 1.5, and the latest xCode. I also use this function extensively without issue. Here is my code to compare with yours. It could be something silly, like the lowercase "c" in camera...

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI, encodingType: Camera.EncodingType.JPEG, targetWidth: 2048, targetHeight: 2048 } );


ScottP

unread,
Mar 26, 2012, 11:14:13 AM3/26/12
to phonegap
Got it working by just calling:
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType:Camera.PictureSourceType.PHOTOLIBRARY});
as zSprawl mentioned. Not sure why the code from the phonegap
documents doesn't work.

On Mar 23, 6:16 am, "Paul D. Clegg" <p.cl...@textmimedia.com> wrote:
> Hi Scott,
>
> I can confirm I am having the same problem with IOS5.1  using PG 1.3.  The
> feature works in the simulator but no on the phone. I am using the latest
> version of xcode.
>
> If i find a fix I will update this thread.
>
>
>
>
>
>
>
> On Wednesday, 21 March 2012 14:02:17 UTC, ScottP wrote:
>
> > I should have specified both devices are running iOS 5.1
>
> > On Mar 21, 8:39 am, ScottP <scott.a.padi...@gmail.com> wrote:
> > > Hey All,
> > > I can't seem to get the camera.getPicture function to work.
> > > I'm using Xcode 4.3.1 on snow leopard.
> > > Phonegap 1.1.0 with JQTouch.
> > > I've tried on actual devices: iPod (4th gen with camera) and iPad2
> > > (with camera).
> > > I don't get any error messages in console or anything.
> > > If I change it to use the capture.captureImage API then the camera
> > > does indeed open and I can save a photo to the camera roll.
> > > But for some reason camera.getPicture is just not working. I'd like to
> > > be able to grab the file URIs from the albums and camera roll.
> > > I added an alert just before navigator.camera.getPicture in the
> > > getPhoto function and it shows up.  When I put the alert after it I
> > > get no alert.
>
> > > I'm using the code straight fromhttp://
> > docs.phonegap.com/​en/1.1.0/phonegap_camera_​camera.md.html#Camera<http://docs.phonegap.com/en/1.1.0/phonegap_camera_camera.md.html#Camera>
Reply all
Reply to author
Forward
0 new messages