mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2026-06-06 00:00:37 +08:00
feat(ios): use PHPickerViewController for iOS 14+ (#937)
- Does not need any permissions for reading images - The PHPickerViewController class is an alternative to UIImagePickerController. PHPickerViewController improves stability and reliability, and includes several benefits to developers and users, such as the following: - Deferred image loading and recovery UI - Reliable handling of large and complex assets, like RAW and panoramic images - User-selectable assets that aren’t available for UIImagePickerController - Configuration of the picker to display only Live Photos - Availability of PHLivePhoto objects without library access - Stricter validations against invalid inputs - See documentation of PHPickerViewController: https://developer.apple.com/documentation/photosui/phpickerviewcontroller?language=objc - Added tests for PHPickerViewController in `CameraTest.m` * Documentation and formatting - Document `takePicture` and `showCameraPicker` in `CDVCamera.m` - A pragmas for UIImagePickerControllerDelegate methods and CLLocationManager methods - Format some long methods declarations to multi-line instead single-line for better readability - Remove unnecessry `dispatch_async(dispatch_get_main_queue() ...` in `takePicture` before calling `showCameraPicker`. This is already done in `showCameraPicker`. - Source out code for permission denied alert dialog when accessing the camera or UIImagePickerController on iOS < 14 for picking images * feat(ios): proper formatting of methods - Use linux brace style: A brace have to be on a new line for method declarations - Remove unnecessary whitespaces in method declrations * doc: readme update - Better document usage descriptions - `NSPhotoLibraryUsageDescription` not needed for iOS 14+ when only picking images - Improve formatting for xml, js - sourceType `SAVEDPHOTOALBUM` is the same as `PHOTOLIBRARY` on Android and iOS 14+ - Use `PHOTOLIBRARY` as sourceType instead of `SAVEDPHOTOALBUM` in photo picker example * Android: Document `SAVEDPHOTOALBUM`` - Make clear that `SAVEDPHOTOALBUM` is the same like `PHOTOLIBRARY` and has only an effect on iOS < 14 - Format code when creating image chooser and document the request code parameter
This commit is contained in:
@@ -77,9 +77,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
private static final int DATA_URL = 0; // Return base64 encoded string
|
||||
private static final int FILE_URI = 1; // Return file uri (content://media/external/images/media/2 for Android)
|
||||
|
||||
private static final int PHOTOLIBRARY = 0; // Choose image from picture library (same as SAVEDPHOTOALBUM for Android)
|
||||
private static final int PHOTOLIBRARY = 0; // Choose image from picture library
|
||||
private static final int CAMERA = 1; // Take picture from camera
|
||||
private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android)
|
||||
private static final int SAVEDPHOTOALBUM = 2; // Same as PHOTOLIBRARY. This settings makes only a difference on iOS older than 14,
|
||||
// where an image can only be chosen from the device's Camera Roll album, with this setting.
|
||||
|
||||
private static final int PICTURE = 0; // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
|
||||
private static final int VIDEO = 1; // allow selection of video only, ONLY RETURNS URL
|
||||
@@ -423,9 +424,15 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
}
|
||||
|
||||
if (this.cordova != null) {
|
||||
this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent,
|
||||
new String(title)), (srcType + 1) * 16 + returnType + 1);
|
||||
this.cordova.startActivityForResult(
|
||||
(CordovaPlugin) this,
|
||||
Intent.createChooser(
|
||||
intent,
|
||||
new String(title)),
|
||||
// Requestcode
|
||||
(srcType + 1) * 16 + returnType + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user