使用未声明的标识符“ kUTTypeMovie”


114

我收到错误消息- 使用未声明的标识符'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];
}

它出什么问题了?

Answers:


291

您必须将框架MobileCoreServices添加到项目中,然后将其导入:

目标C:

#import <MobileCoreServices/MobileCoreServices.h>

那将使问题消失。

斯威夫特4:

import MobileCoreServices

1
@import MobileCoreServices;-对于Objective-C
Ganpat,

37

迅速

import MobileCoreServices

目标c

#import <MobileCoreServices/MobileCoreServices.h>

20

我是iOS开发和xcode的新手,花了一些时间试图找出为什么仅导入无法正常工作。在与我团队中经验更丰富的成员一起找出问题之后,我发现您不仅必须包括

#import <MobileCoreServices/MobileCoreServices.h>

但是您还必须将二进制文件链接到MobileCoreServices框架的库,以链接到项目的构建阶段。

希望这可以帮助!我确实在执行此操作时需要此信息。


3

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)
}

0
  1. 如果尚未添加MobileCoreServices.framework,请添加它。选择您的目标,然后将链接的二进制文件添加到库中。
  2. #import <MobileCoreServices/MobileCoreServices.h>

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.