Use of undeclared identifier 'kUTTypeMovie'

IosCocoa TouchMobilecoreservices

Ios Problem Overview


I am getting the error message - 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?

Ios Solutions


Solution 1 - Ios

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

Objective C:

#import <MobileCoreServices/MobileCoreServices.h>

That will make the problem go away.

Swift 4:

import MobileCoreServices

Solution 2 - Ios

swift

import MobileCoreServices

objective c

#import <MobileCoreServices/MobileCoreServices.h>

Solution 3 - Ios

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

#import <MobileCoreServices/MobileCoreServices.h>

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

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

Solution 4 - Ios

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

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:

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

Solution 5 - Ios

  1. Add MobileCoreServices.framework if not added already. Select your target and add linked binaries with library.
  2. Add #import <MobileCoreServices/MobileCoreServices.h>

Solution 6 - Ios

import MobileCoreServices for swift
@import MobileCoreServices; for objective c

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAshish AgarwalView Question on Stackoverflow
Solution 1 - IosThe dudeView Answer on Stackoverflow
Solution 2 - IosbudiDinoView Answer on Stackoverflow
Solution 3 - IosJosh LoweView Answer on Stackoverflow
Solution 4 - IosFrank EnoView Answer on Stackoverflow
Solution 5 - IosRam G.View Answer on Stackoverflow
Solution 6 - IosNaqeeb AhmedView Answer on Stackoverflow