我收到错误消息 - 使用未声明的标识符'kUTTypeMovie'
在下面的代码中 -
-(IBAction)selectVideo:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
它出什么问题了?
我是iOS开发和xcode的新手,花了一些时间试图找出导入无效的原因。在与我的团队中经验丰富的成员解决问题后,我发现您不仅必须包含这些问题
#import <MobileCoreServices/MobileCoreServices.h>
但您还必须将二进制文件链接到MobileCoreServices框架的库,直到项目的构建阶段。
希望这可以帮助!当我这样做时,我确实需要这些信息。
Swift 4回答,带摄像机代码和imagePicker代表:
import MobileCoreServices
打开摄像机
@IBAction func openVideoCamera(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.videoMaximumDuration = 10 // or whatever you want
imagePicker.videoQuality = .typeMedium
imagePicker.allowsEditing = false
present(imagePicker, animated: true, completion: nil)
}
ImagePicker委托:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let mediaType = info[UIImagePickerControllerMediaType] as AnyObject
if mediaType as! String == kUTTypeMovie as String {
let videoURL = info[UIImagePickerControllerMediaURL] as? URL
print("VIDEO URL: \(videoURL!)")
}
dismiss(animated: true, completion: nil)
}
#import <MobileCoreServices/MobileCoreServices.h>
import MobileCoreServices
快速
@import MobileCoreServices;
为目标c