RCTImagePickerManager crash on image from CameraRoll
Summary: Image from CameraRoll haven't UIImagePickerControllerReferenceURL. So we need to save it to PhotoAlbums first. To save image I've used the same method from RCTCameraRollManager. Closes https://github.com/facebook/react-native/pull/4412 Reviewed By: svcscm Differential Revision: D2707249 Pulled By: nicklockwood fb-gh-sync-id: eee683bd4179700bed46ebf45e569197f3ad2077
This commit is contained in:
parent
aad40b8b1d
commit
d08727d99f
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
#import "RCTImagePickerManager.h"
|
||||
#import "RCTImageStoreManager.h"
|
||||
|
||||
#import "RCTConvert.h"
|
||||
#import "RCTRootView.h"
|
||||
|
@ -32,6 +33,8 @@
|
|||
|
||||
RCT_EXPORT_MODULE(ImagePickerIOS);
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
{
|
||||
return dispatch_get_main_queue();
|
||||
|
@ -101,9 +104,26 @@ RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config
|
|||
- (void)imagePickerController:(UIImagePickerController *)picker
|
||||
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
|
||||
{
|
||||
[self _dismissPicker:picker args:@[
|
||||
[info[UIImagePickerControllerReferenceURL] absoluteString]
|
||||
]];
|
||||
// Image from PhotoLibrary
|
||||
NSString *imageUri = [info[UIImagePickerControllerReferenceURL] absoluteString];
|
||||
if (imageUri) {
|
||||
[self _dismissPicker:picker args:@[imageUri]];
|
||||
|
||||
} else {
|
||||
// Image from CameraRoll hasn't uri.
|
||||
// We need to save it to the store first.
|
||||
UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
|
||||
|
||||
// WARNING: Using imageStoreManager causes memory leak
|
||||
// because image isn't removed from store once we're done using it
|
||||
[_bridge.imageStoreManager storeImage:originalImage withBlock:^(NSString *tempImageTag) {
|
||||
if (!tempImageTag) {
|
||||
[self _dismissPicker:picker args:nil];
|
||||
return;
|
||||
}
|
||||
[self _dismissPicker:picker args:@[tempImageTag]];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
|
||||
|
|
Loading…
Reference in New Issue