Picking images & videos from the iOS photo album with RubyMotion

rubymotion, ios, ruby, technical

We’ve been working on a video app for a client of ours. We came across the need to select videos from the iOS camera roll/photo album. It was one of those trial and error type (-frustrating) endeavours. We thought we’d write down our findings in the hope of saving someone else from the same frustration.

As with a lot of things, it ended up being pretty simple in the end.

First we use the UIImagePickerController to check if the source type we need is available and then present the picker. The media types weren’t obvious at first. Check out the docs for more configuration options.

Then when that’s complete, you can pick up the URL of the selected video. You can copy it like we do here or do whatever else you need.

defimagePickerController(picker,didFinishPickingMediaWithInfo:info)video_url=info.objectForKeyUIImagePickerControllerMediaURLfileManager=NSFileManager.defaultManagerfileManager.copyItemAtPath(video_url.path,toPath:"video.mp4".document_path,error:nil)picker.dismissViewControllerAnimated(true,completion:nil)# any other actionend