How to record video files in your iOS App

Recording video is very similar to taking a picture with the built-in device camera: we can use the UIImagePickerController – all we do is to specify the video camera for picking actions.

Here’s how can create it:

Note the very first line for importing the Mobile Core Services framework – it needs to be imported and linked to in your project. This is not mentioned anywhere in the official Apple Documentation at the time of writing! We need this to specify the media types array for the image picker. With it we’re saying “only allow movies”. Without the framework Xcode won’t know what kUTTypeMovie is.

If the device doesn’t have a camera this method would crash (Simulator for example, or iPhone 3G), hence the if/then statement.

When the picker is finished you can access the movie URLs in its delegate method which we need to conform, just as we do with picking pictures:

Here we create a new URL in our Documents directory (via the grabFileURL method), turn movie URL into data, and use an NSData method to save our video data into our own URL. In addition and for demonstration we’re also saving our video to the Camera Roll.

The last line dismisses the picker. We do the same when the user hits cancel.

There’s a quick and dirty Demo Project on GitHub to illustrate all this.

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.