使用未声明的标识符'kUTTypeMovie'

问题描述 投票:103回答:6

我收到错误消息 - 使用未声明的标识符'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 cocoa-touch mobilecoreservices
6个回答
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>

0
投票

import MobileCoreServices快速 @import MobileCoreServices;为目标c

© www.soinside.com 2019 - 2024. All rights reserved.