Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTImagePickerManager.h"
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <MobileCoreServices/UTCoreTypes.h>
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTImageStoreManager.h>
|
|
|
|
#import <React/RCTRootView.h>
|
|
|
|
#import <React/RCTUtils.h>
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
@interface RCTImagePickerManager () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTImagePickerManager
|
|
|
|
{
|
2015-11-03 22:45:46 +00:00
|
|
|
NSMutableArray<UIImagePickerController *> *_pickers;
|
|
|
|
NSMutableArray<RCTResponseSenderBlock> *_pickerCallbacks;
|
|
|
|
NSMutableArray<RCTResponseSenderBlock> *_pickerCancelCallbacks;
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE(ImagePickerIOS);
|
|
|
|
|
2015-12-01 10:10:20 +00:00
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
2015-11-16 11:15:31 +00:00
|
|
|
- (dispatch_queue_t)methodQueue
|
|
|
|
{
|
|
|
|
return dispatch_get_main_queue();
|
|
|
|
}
|
|
|
|
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
RCT_EXPORT_METHOD(canRecordVideos:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
2015-11-03 22:45:46 +00:00
|
|
|
NSArray<NSString *> *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
callback(@[@([availableMediaTypes containsObject:(NSString *)kUTTypeMovie])]);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(canUseCamera:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
callback(@[@([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])]);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(openCameraDialog:(NSDictionary *)config
|
|
|
|
successCallback:(RCTResponseSenderBlock)callback
|
|
|
|
cancelCallback:(RCTResponseSenderBlock)cancelCallback)
|
|
|
|
{
|
2015-09-22 17:43:56 +00:00
|
|
|
if (RCTRunningInAppExtension()) {
|
|
|
|
cancelCallback(@[@"Camera access is unavailable in an app extension"]);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 22:45:46 +00:00
|
|
|
|
2015-08-17 14:35:34 +00:00
|
|
|
UIImagePickerController *imagePicker = [UIImagePickerController new];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
imagePicker.delegate = self;
|
|
|
|
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
|
|
|
2015-11-14 18:25:00 +00:00
|
|
|
if ([RCTConvert BOOL:config[@"videoMode"]]) {
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
|
|
|
|
}
|
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
[self _presentPicker:imagePicker
|
|
|
|
successCallback:callback
|
|
|
|
cancelCallback:cancelCallback];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config
|
|
|
|
successCallback:(RCTResponseSenderBlock)callback
|
|
|
|
cancelCallback:(RCTResponseSenderBlock)cancelCallback)
|
|
|
|
{
|
2015-09-22 17:43:56 +00:00
|
|
|
if (RCTRunningInAppExtension()) {
|
|
|
|
cancelCallback(@[@"Image picker is currently unavailable in an app extension"]);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 22:45:46 +00:00
|
|
|
|
2015-08-17 14:35:34 +00:00
|
|
|
UIImagePickerController *imagePicker = [UIImagePickerController new];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
imagePicker.delegate = self;
|
|
|
|
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
NSMutableArray<NSString *> *allowedTypes = [NSMutableArray new];
|
2015-11-14 18:25:00 +00:00
|
|
|
if ([RCTConvert BOOL:config[@"showImages"]]) {
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
[allowedTypes addObject:(NSString *)kUTTypeImage];
|
|
|
|
}
|
2015-11-14 18:25:00 +00:00
|
|
|
if ([RCTConvert BOOL:config[@"showVideos"]]) {
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
[allowedTypes addObject:(NSString *)kUTTypeMovie];
|
|
|
|
}
|
|
|
|
|
|
|
|
imagePicker.mediaTypes = allowedTypes;
|
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
[self _presentPicker:imagePicker
|
|
|
|
successCallback:callback
|
|
|
|
cancelCallback:cancelCallback];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)imagePickerController:(UIImagePickerController *)picker
|
2015-11-14 18:25:00 +00:00
|
|
|
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
{
|
2016-02-09 12:44:43 +00:00
|
|
|
NSString *mediaType = info[UIImagePickerControllerMediaType];
|
|
|
|
BOOL isMovie = [mediaType isEqualToString:(NSString *)kUTTypeMovie];
|
|
|
|
NSString *key = isMovie ? UIImagePickerControllerMediaURL : UIImagePickerControllerReferenceURL;
|
|
|
|
NSURL *imageURL = info[key];
|
2016-05-16 17:58:16 +00:00
|
|
|
UIImage *image = info[UIImagePickerControllerOriginalImage];
|
|
|
|
NSNumber *width = 0;
|
|
|
|
NSNumber *height = 0;
|
|
|
|
if (image) {
|
|
|
|
height = @(image.size.height);
|
|
|
|
width = @(image.size.width);
|
|
|
|
}
|
2016-02-09 12:44:43 +00:00
|
|
|
if (imageURL) {
|
2016-05-16 17:58:16 +00:00
|
|
|
[self _dismissPicker:picker args:@[imageURL.absoluteString, RCTNullIfNil(height), RCTNullIfNil(width)]];
|
2016-02-09 12:44:43 +00:00
|
|
|
return;
|
2015-12-01 10:10:20 +00:00
|
|
|
}
|
2016-02-09 12:44:43 +00:00
|
|
|
|
|
|
|
// This is a newly taken image, and doesn't have a URL yet.
|
|
|
|
// We need to save it to the image store first.
|
|
|
|
UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
|
|
|
|
|
|
|
|
// WARNING: Using ImageStoreManager may cause a memory leak because the
|
|
|
|
// image isn't automatically removed from store once we're done using it.
|
|
|
|
[_bridge.imageStoreManager storeImage:originalImage withBlock:^(NSString *tempImageTag) {
|
2016-05-16 17:58:16 +00:00
|
|
|
[self _dismissPicker:picker args:tempImageTag ? @[tempImageTag, height, width] : nil];
|
2016-02-09 12:44:43 +00:00
|
|
|
}];
|
2015-11-25 11:09:00 +00:00
|
|
|
}
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
|
|
|
|
{
|
|
|
|
[self _dismissPicker:picker args:nil];
|
|
|
|
}
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
- (void)_presentPicker:(UIImagePickerController *)imagePicker
|
|
|
|
successCallback:(RCTResponseSenderBlock)callback
|
|
|
|
cancelCallback:(RCTResponseSenderBlock)cancelCallback
|
|
|
|
{
|
|
|
|
if (!_pickers) {
|
|
|
|
_pickers = [NSMutableArray new];
|
|
|
|
_pickerCallbacks = [NSMutableArray new];
|
|
|
|
_pickerCancelCallbacks = [NSMutableArray new];
|
|
|
|
}
|
|
|
|
|
|
|
|
[_pickers addObject:imagePicker];
|
|
|
|
[_pickerCallbacks addObject:callback];
|
|
|
|
[_pickerCancelCallbacks addObject:cancelCallback];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
|
2016-05-21 00:03:34 +00:00
|
|
|
UIViewController *rootViewController = RCTPresentedViewController();
|
2015-11-25 11:09:00 +00:00
|
|
|
[rootViewController presentViewController:imagePicker animated:YES completion:nil];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
- (void)_dismissPicker:(UIImagePickerController *)picker args:(NSArray *)args
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
{
|
|
|
|
NSUInteger index = [_pickers indexOfObject:picker];
|
2015-11-30 18:28:49 +00:00
|
|
|
RCTResponseSenderBlock successCallback = _pickerCallbacks[index];
|
|
|
|
RCTResponseSenderBlock cancelCallback = _pickerCancelCallbacks[index];
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
|
|
|
|
[_pickers removeObjectAtIndex:index];
|
|
|
|
[_pickerCallbacks removeObjectAtIndex:index];
|
|
|
|
[_pickerCancelCallbacks removeObjectAtIndex:index];
|
|
|
|
|
2016-05-21 00:03:34 +00:00
|
|
|
UIViewController *rootViewController = RCTPresentedViewController();
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
[rootViewController dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
|
2015-11-30 18:28:49 +00:00
|
|
|
if (args) {
|
|
|
|
successCallback(args);
|
|
|
|
} else {
|
|
|
|
cancelCallback(@[]);
|
|
|
|
}
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 10:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|