需要导入框架AVFoundation/AVFoundation.h###
屏幕快照 2016-08-02 上午8.35.41.png
//在选取的照片的过程中必须要allowsEditing才可以上传照片
//如果既有照片又有视屏则需要制定媒体类型(KUTType类型)
imagePickerC.mediaTypes = @"public.image" //图片类型
imagePickerC.mediaTypes = @"public.movie"//视屏类型
/*
sourceType 的几个属性:
UIImagePickerControllerSourceTypePhotoLibrary 相册,本地视屏
UIImagePickerControllerSourceTypeCamera 拍照 摄像
UIImagePickerControllerSourceTypeSavedPhotosAlbum 时刻
*/
代理方法###
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
/**
如果既有照片又有视屏则需要判断是哪种类型,字典info中存的几个重要的关键字:
UIImagePickerControllerMediaType //媒体类型,用来判断哪种媒体
UIImagePickerControllerEditedImage:编辑后的图片
UIImagePickerControllerOriginalImage:编辑前的图片
UIImagePickerControllerMediaURL //媒体的url地址
**/
//判断是否有摄像头,rear为后置摄像头
BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
//保存到相册中,selector中的这个方法是系统固定的
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
//需要实现这个方法
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if (error == nil) {
NSLog(@"成功");
}
}