I’ve done the installing similar to you however haven’t tried an ionic serve yet because in Visual Code intellisense is saying that ‘property getPicture’ is not a type on Camera:
let options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 350,
targetHeight: 350,
correctOrientation: true,
saveToPhotoAlbum: false
}
Camera.getPicture(options).then...
(though it doesn’t complain about the properties of Camera defined in my options).
Looking at the index.d.ts for the camera plugin shows it’s only picking up the following properties:
declare var Camera: {
// Camera constants, defined in Camera plugin
DestinationType: {
DATA_URL: number;
FILE_URI: number;
NATIVE_URI: number
}
Direction: {
BACK: number;
FRONT: number;
}
EncodingType: {
JPEG: number;
PNG: number;
}
MediaType: {
PICTURE: number;
VIDEO: number;
ALLMEDIA: number;
}
PictureSourceType: {
PHOTOLIBRARY: number;
CAMERA: number;
SAVEDPHOTOALBUM: number;
}
// Used only on iOS
PopoverArrowDirection: {
ARROW_UP: number;
ARROW_DOWN: number;
ARROW_LEFT: number;
ARROW_RIGHT: number;
ARROW_ANY: number;
}
How do I instead get my code to ‘see’ the property of the Camera interface as also defined in index.d.ts?
interface Camera {
/**
* Removes intermediate photos taken by the camera from temporary storage.
* @param onSuccess Success callback, that called when cleanup succeeds.
* @param onError Error callback, that get an error message.
*/
cleanup(
onSuccess: () => void,
onError: (message: string) => void): void;
/**
* Takes a photo using the camera, or retrieves a photo from the device's image gallery.
* @param cameraSuccess Success callback, that get the image
* as a base64-encoded String, or as the URI for the image file.
* @param cameraError Error callback, that get an error message.
* @param cameraOptions Optional parameters to customize the camera settings.
*/
getPicture(
cameraSuccess: (data: string) => void,
cameraError: (message: string) => void,
cameraOptions?: CameraOptions): void;
// Next will work only on iOS
//getPicture(
// cameraSuccess: (data: string) => void,
// cameraError: (message: string) => void,
// cameraOptions?: CameraOptions): CameraPopoverHandle;
}
The ‘documentation’ says I should be able to just use Camera.getPicture:
http://ionicframework.com/docs/v2/native/Camera/
I have not used any import call at the start of my page as I am not sure it’s necessary (docs don’t say so).
Thanks to anyone who can advise!
UPDATE: I found that I needed to install ionic-native as advised here:
and then import using
import {Camera} from 'ionic-native';
for Camera.getPicture to be recognised by the intellisense. Unfortunately now the Camera properties defined in my options such as DestinationType are not being recognised by the intellisense (I’ve inverted my problem!). I’ll update again if I get that sorted. Argh, can’t wait for some thorough documentation!
UPDATE 2: In node_modules -> ionic-native -> dist -> plugins -> camera.d.ts it shows that the properties destinationType, sourceType and encodingType are expecting numbers. Thus, as per the comments in that file, for my situation I needed to specify:
let options = {
quality: 100,
destinationType: 0,
sourceType: 1,
allowEdit: false,
encodingType: 0,
targetWidth: 350,
targetHeight: 350,
correctOrientation: true,
saveToPhotoAlbum: false
}