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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11755494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:31:24  来源:igfitidea点击:

Use of undeclared identifier 'kUTTypeMovie'

ioscocoa-touchmobilecoreservices

提问by Ashish Agarwal

I am getting the error message - Use of undeclared identifier 'kUTTypeMovie'

我收到错误消息 - Use of undeclared identifier 'kUTTypeMovie'

in the below code -

在下面的代码中 -

-(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];
}

What's wrong with it?

它出什么问题了?

回答by The dude

You have to add the framework MobileCoreServices to the project, and then import it:

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

Objective C:

目标 C:

#import <MobileCoreServices/MobileCoreServices.h>

That will make the problem go away.

这将使问题消失。

Swift 4:

斯威夫特 4:

import MobileCoreServices

回答by budidino

swift

迅速

import MobileCoreServices

objective c

目标 c

#import <MobileCoreServices/MobileCoreServices.h>

回答by Josh Lowe

I am a novice at iOS development and xcode and spent some time trying to find out why just the import was not working. After figuring out the problem with a more experienced member of my team I found out that not only must you include

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

#import <MobileCoreServices/MobileCoreServices.h>

but you must also link binaries to the library of the MobileCoreServices framework to the build phases of your project.

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

Hope this helps! I sure needed this info when I was doing this.

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

回答by Frank Dev

Swift 4answer, with video camera code and imagePicker delegate:

Swift 4答案,带有摄像机代码和 imagePicker 委托:

import MobileCoreServices

Open Video Camera

打开摄像机

   @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 delegate:

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

回答by Ram G.

  1. Add MobileCoreServices.framework if not added already. Select your target and add linked binaries with library.
  2. Add #import <MobileCoreServices/MobileCoreServices.h>
  1. 如果尚未添加,请添加 MobileCoreServices.framework。选择您的目标并添加带有库的链接二进制文件。
  2. 添加 #import <MobileCoreServices/MobileCoreServices.h>

回答by Naqeeb Ahmed

import MobileCoreServicesfor swift
@import MobileCoreServices;for objective c

import MobileCoreServices对于 swift
@import MobileCoreServices;目标 c