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

iOS Camera API

I am new to iOS development, and right now I am working in this app. I have finalized the camera Api using UIImagePickerController. However, what I am trying to do is to make the user store the picture he/she took in the phone and I will create an internal SQLite3 database Store the path of where that picture is stored on the phone in the database (not the picture itself)and then Store all the info in the database. Please if you can just provide me link tutorial or any guidance, I will be very grateful. I have checked online and in stack-overflow, I could not found the answer I am looking for.

Here my Camera API code:

ViewConroller.H

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate,         UIImagePickerControllerDelegate>
@property (retain, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet UIButton *Camera;

-(IBAction)buttonPressed:(UIButton *)sender;
@end

ViewController.M

 #import "ViewController.h"
 @interface ViewController ()

 @end

 @implementation ViewController

  - (void)viewDidLoad
  {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController     isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                          message:@"Device has no camera"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles: nil];

    [myAlertView show];

}


// Do any additional setup after loading the view, typically from a nib.
 }

 - (void)didReceiveMemoryWarning
 {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }
 - (IBAction)buttonPressed:(UIButton *)sender {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentViewController:picker animated:YES completion:NULL];

  }
   - (void)imagePickerController:(UIImagePickerController *)picker    didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;

[picker dismissViewControllerAnimated:YES completion:NULL];

 }

 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

[picker dismissViewControllerAnimated:YES completion:NULL];

 }

  - (void)dealloc {
[_imageView release];
[super dealloc];
 }


 @end

I did it using storyboard, Xcode 4.6.3

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi Abdulmajeed,

Don't know if you've seen, but we just released a new iOS project that talks about using UIImagePickerController. Here's the whole course: http://teamtreehouse.com/library/ios-development/build-a-selfdestructing-message-iphone-app

And here's the stage that talks about storing an image or video in the Saved Photos album: http://teamtreehouse.com/library/ios-development/build-a-selfdestructing-message-app/capturing-photo-and-video-using-uiimagepickercontroller

At that point, you would just need to store some additional information in a SQLite database. We don't have anything that covers that, although you might be interested in Core Data in iOS Foundations. For SQLite, I'd check out this tutorial by Ray Wenderlich, who always has awesome stuff: http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app

can I use parse.com instead of SQLite?

Ben, Thank you very much. I will watch the tutorials