Skip to content

Commit fad2b37

Browse files
skysky
authored andcommitted
change file picker
1 parent 436bb2c commit fad2b37

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ fastlane/screenshots
6161

6262
iOSInjectionProject/
6363
node_modules/**/*
64+
.DS_Store
65+
android/react-native-document-picker.iml

ios/RNDocumentPicker/RNDocumentPicker.m

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#import "RNDocumentPicker.h"
22

3+
#import <MobileCoreServices/MobileCoreServices.h>
4+
35
#if __has_include(<React/RCTConvert.h>)
46
#import <React/RCTConvert.h>
57
#import <React/RCTBridge.h>
@@ -11,7 +13,7 @@
1113
#define IDIOM UI_USER_INTERFACE_IDIOM()
1214
#define IPAD UIUserInterfaceIdiomPad
1315

14-
@interface RNDocumentPicker () <UIDocumentMenuDelegate,UIDocumentPickerDelegate>
16+
@interface RNDocumentPicker () <UINavigationControllerDelegate,UIImagePickerControllerDelegate> //<UIDocumentMenuDelegate,UIDocumentPickerDelegate>
1517
@end
1618

1719

@@ -37,9 +39,56 @@ - (dispatch_queue_t)methodQueue
3739
}
3840

3941
RCT_EXPORT_MODULE()
40-
4142
RCT_EXPORT_METHOD(show:(NSDictionary *)options
4243
callback:(RCTResponseSenderBlock)callback) {
44+
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
45+
imagePicker.delegate = self;
46+
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
47+
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
48+
49+
[composeCallbacks addObject:callback];
50+
51+
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
52+
while (topController.presentedViewController) {
53+
topController = topController.presentedViewController;
54+
}
55+
[topController presentViewController:imagePicker animated:YES completion:nil];
56+
//[self presentViewController:imagePicker animated: YES completion: nil];
57+
}
58+
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
59+
{
60+
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
61+
NSString *moviePath;
62+
NSMutableDictionary* result = [NSMutableDictionary dictionary];
63+
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
64+
NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
65+
moviePath = [videoUrl path];
66+
67+
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
68+
// UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
69+
}
70+
[result setValue:moviePath forKey:@"uri"];
71+
[result setValue:@"" forKey:@"fileName"];
72+
[result setValue:@"" forKey:@"fileSize"];
73+
}else{
74+
75+
}
76+
[picker dismissViewControllerAnimated:YES completion:nil];
77+
78+
RCTResponseSenderBlock callback = [composeCallbacks lastObject];
79+
[composeCallbacks removeLastObject];
80+
81+
callback(@[[NSNull null], result]);
82+
}
83+
84+
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
85+
{
86+
[picker dismissViewControllerAnimated:YES completion:nil];
87+
}
88+
89+
/*
90+
RCT_EXPORT_METHOD(show1:(NSDictionary *)options
91+
callback:(RCTResponseSenderBlock)callback) {
4392
4493
NSArray *allowedUTIs = [RCTConvert NSArray:options[@"filetype"]];
4594
UIDocumentMenuViewController *documentPicker = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:(NSArray *)allowedUTIs inMode:UIDocumentPickerModeImport];
@@ -113,5 +162,5 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocum
113162
[url stopAccessingSecurityScopedResource];
114163
}
115164
}
116-
165+
*/
117166
@end

0 commit comments

Comments
 (0)