From 96602e9354e408b90f2ff119b15697c9e48491d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ali=20y=C3=BCksel?= Date: Thu, 2 Nov 2017 18:34:06 +0000 Subject: [PATCH 1/2] Handle user pressing cancel button for ios/ add Error for Android --- src/camera.android.ts | 3 +++ src/camera.ios.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/camera.android.ts b/src/camera.android.ts index 3ace553..b8f6870 100644 --- a/src/camera.android.ts +++ b/src/camera.android.ts @@ -125,6 +125,9 @@ export let takePicture = function (options?): Promise { keepAspectRatio: shouldKeepAspectRatio }; resolve(asset); + } else if (resultCode === android.app.Activity.RESULT_CANCELED) { + // User cancelled the image capture + reject(new Error("cancelled")); } }); diff --git a/src/camera.ios.ts b/src/camera.ios.ts index ac7d980..888c637 100644 --- a/src/camera.ios.ts +++ b/src/camera.ios.ts @@ -12,19 +12,22 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic } private _callback: (result?) => void; + private _errorCallback: (result?) => void; private _width: number; private _height: number; private _keepAspectRatio: boolean; private _saveToGallery: boolean; - public initWithCallback(callback: (result?) => void): UIImagePickerControllerDelegateImpl { + public initWithCallback(callback: (result?) => void,errorCallback: (result?) => void): UIImagePickerControllerDelegateImpl { this._callback = callback; + this._errorCallback = errorCallback; return this; } - public initWithCallbackAndOptions(callback: (result?) => void, options?): UIImagePickerControllerDelegateImpl { + public initWithCallbackAndOptions(callback: (result?) => void,errorCallback: (result?) => void, options?): UIImagePickerControllerDelegateImpl { this._callback = callback; + this._errorCallback = errorCallback; if (options) { this._width = options.width; this._height = options.height; @@ -117,6 +120,7 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic imagePickerControllerDidCancel(picker): void { picker.presentingViewController.dismissViewControllerAnimatedCompletion(true, null); listener = null; + this._errorCallback(new Error("cancelled")); } } @@ -144,13 +148,13 @@ export let takePicture = function (options): Promise { if (reqWidth && reqHeight) { listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions( - resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio, saveToGallery: saveToGallery }); + resolve, reject, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio, saveToGallery: saveToGallery }); } else if (saveToGallery) { listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions( - resolve, { saveToGallery: saveToGallery, keepAspectRatio: keepAspectRatio }); + resolve,reject, { saveToGallery: saveToGallery, keepAspectRatio: keepAspectRatio }); } else { - listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve); + listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve,reject); } imagePickerController.delegate = listener; From 3aba531443c16591a744c844b77d38a2f79f8c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ali=20y=C3=BCksel?= Date: Fri, 3 Nov 2017 14:38:06 +0000 Subject: [PATCH 2/2] #27.1 failed --- src/camera.ios.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/camera.ios.ts b/src/camera.ios.ts index 888c637..9f0f2d9 100644 --- a/src/camera.ios.ts +++ b/src/camera.ios.ts @@ -19,13 +19,13 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic private _keepAspectRatio: boolean; private _saveToGallery: boolean; - public initWithCallback(callback: (result?) => void,errorCallback: (result?) => void): UIImagePickerControllerDelegateImpl { + public initWithCallback(callback: (result?) => void, errorCallback: (result?) => void): UIImagePickerControllerDelegateImpl { this._callback = callback; this._errorCallback = errorCallback; return this; } - public initWithCallbackAndOptions(callback: (result?) => void,errorCallback: (result?) => void, options?): UIImagePickerControllerDelegateImpl { + public initWithCallbackAndOptions(callback: (result?) => void, errorCallback: (result?) => void, options?): UIImagePickerControllerDelegateImpl { this._callback = callback; this._errorCallback = errorCallback; if (options) { @@ -151,10 +151,10 @@ export let takePicture = function (options): Promise { resolve, reject, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio, saveToGallery: saveToGallery }); } else if (saveToGallery) { listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions( - resolve,reject, { saveToGallery: saveToGallery, keepAspectRatio: keepAspectRatio }); + resolve, reject, { saveToGallery: saveToGallery, keepAspectRatio: keepAspectRatio }); } else { - listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve,reject); + listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve, reject); } imagePickerController.delegate = listener;