Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Capturing Photo and Video Using UIImagePickerController Presenting the UIImagePickerController (Camera View)

Dee Greene
Dee Greene
8,508 Points

Presenting both camera AND photo library

How would I go about presenting the camera to the user as well as an option to select a picture that is already stored on their device? Currently we are only doing one or the other.

1 Answer

Brayden Kness
Brayden Kness
12,492 Points

You would have to make a custom view controller with the UIImagePickerControllerDelegate. Here is a good tutorial part 1 and part 2. Then you would add a button that could open the photo library.

P.S. Not in the tutorial but if you add a button in your storyboard then you to replace

cameraView.layer.addSublayer(previewLayer!)

with

cameraView.layer.insertSublayer(previewLayer!, atIndex: 0)

this will keep the buttons above the preview layer.

Dee Greene
Dee Greene
8,508 Points

Thank you! Do you happen to know of any great tutorials like this that are in Objective-C since this is what the rest of the code is in

Brayden Kness
Brayden Kness
12,492 Points

Oh sorry didn't realize that. I will translate it and post it here in a little while.

Dee Greene
Dee Greene
8,508 Points

thank you so much!

Brayden Kness
Brayden Kness
12,492 Points

Here is an example project the only thing I didn't add is the code for pulling up the photo library but you will see the place to add it

Dee Greene
Dee Greene
8,508 Points

thank you. this is nice. I'm sure i can mess w/ this to get it out how i want it. do you happen to know how to turn it to the front camera as well? and how would you capture a video?