Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIImagePicker 涉及到相机相册权限
#import <MobileCoreServices/MobileCoreServices.h>
@interface <#XX#>() <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIImagePickerController *imagePicker;
@property (nonatomic, strong) UIImagePickerController *cameraPicker;
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
NSString *mediaType = info[UIImagePickerControllerMediaType];
UIImage *orgImage = nil;
if (([mediaType isEqualToString:(NSString *)kUTTypeImage])) {
orgImage = info[UIImagePickerControllerOriginalImage];
}
[picker dismissViewControllerAnimated:YES
completion:^{
if(orgImage) {
}
}];
//NSURL *mediaPath = info[UIImagePickerControllerMediaURL]; //视频
//[picker dismissViewControllerAnimated:YES
// completion:^{
//
// }];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES
completion:nil];
}
- (UIImagePickerController *)imagePicker {
if (_imagePicker == nil) {
_imagePicker = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
#elif TARGET_OS_IPHONE
_imagePicker.modalPresentationStyle = UIModalPresentationOverFullScreen;
_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePicker.mediaTypes = @[(NSString *)kUTTypeImage];
//_imagePicker.mediaTypes = @[(NSString *)kUTTypeMovie];
#endif
_imagePicker.delegate = self;
}
return _imagePicker;
}
- (UIImagePickerController *)cameraPicker {
if (_cameraPicker == nil) {
_cameraPicker = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
#elif TARGET_OS_IPHONE
_cameraPicker.modalPresentationStyle = UIModalPresentationOverFullScreen;
_cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_cameraPicker.mediaTypes = @[(NSString *)kUTTypeImage];
//_cameraPicker.mediaTypes = @[(NSString *)kUTTypeMovie]; //拍摄视频
#endif
_cameraPicker.delegate = self;
}
return _cameraPicker;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.