121

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

它出什么问题了?

4

6 回答 6

310

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

目标 C:

#import <MobileCoreServices/MobileCoreServices.h>

这将使问题消失。

斯威夫特 4:

import MobileCoreServices
于 2012-08-01T08:46:19.250 回答
38

迅速

import MobileCoreServices

目标c

#import <MobileCoreServices/MobileCoreServices.h>
于 2016-10-17T14:24:17.713 回答
20

我是 iOS 开发和 xcode 的新手,我花了一些时间试图找出为什么只是导入不起作用。在与我团队中一位更有经验的成员一起找出问题后,我发现你不仅必须包括

#import <MobileCoreServices/MobileCoreServices.h>

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

希望这可以帮助!当我这样做时,我确实需要这些信息。

于 2012-08-03T18:20:08.137 回答
4

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)
}
于 2018-05-29T05:59:14.637 回答
1
  1. 如果尚未添加,请添加 MobileCoreServices.framework。选择您的目标并添加带有库的链接二进制文件。
  2. 添加#import <MobileCoreServices/MobileCoreServices.h>
于 2018-06-14T17:04:47.060 回答
1

import MobileCoreServices快速
@import MobileCoreServices;实现目标 c

于 2019-04-09T05:38:42.947 回答