diff --git a/ionic/platform/camera/camera.ts b/ionic/platform/camera/camera.ts index e0427f9d66..683b1fc58b 100644 --- a/ionic/platform/camera/camera.ts +++ b/ionic/platform/camera/camera.ts @@ -2,6 +2,21 @@ import * as util from 'ionic/util'; import {NativePlugin} from '../plugin'; +/** + * Take a photo or capture video. + * + * Requires Cordova plugin: `cordova-plugin-camera`. For more info, please see the [Cordova Camera Plugin Docs](https://github.com/apache/cordova-plugin-camera). + * + * @usage + * ```js + * Camera.getPicture(options).then((imageData) => { + * // imageData is either a base64 encoded string or a file URI + * // If it's base64: + * let base64Image = "data:image/jpeg;base64," + imageData; + * }, (err) => { + * }); + * ``` + */ @NativePlugin({ name: 'Camera', platforms: ['ios', 'android'], @@ -13,6 +28,21 @@ import {NativePlugin} from '../plugin'; } }) export class Camera { + /** + * Let the user take a photo or capture video. + * + * @param options {object} options for the photo. Of the form (with defaults): + * { + * quality: 80, + * destinationType: window.Camera.DestinationType.DATA_URL, + * sourceType: window.Camera.PictureSourceType.CAMERA (VIDEO or ALLMEDIA for both), + * allowEdit: true, + * encodingType: window.Camera.EncodingType.JPEG, + * popoverOptions: window.CameraPopoverOptions, + * saveToPhotoAlbum: false + * } + * @return {Promise} resolving with data or rejecting on error + */ static getPicture(options) { return new Promise((resolve, reject) => { if (!navigator.camera) { @@ -38,6 +68,12 @@ export class Camera { }, options); }); } + + /** + * If using FILE_URI and taking photos, photos will be stored temporarily. To + * remove them, call cleanup when the camera session is finished. + * @return {Promise} + */ static cleanup() { return new Promise((resolve, reject) => { navigator.camera.cleanup(function () {