Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
//
// DSPhotoController.m
// DoodleStash
//
// Created by Andrei Taraschuk on 11/24/12.
// Copyright (c) 2012 Andrei Taraschuk. All rights reserved.
//
#import "DSPhotoController.h"
#import "DSConfirmController.h"
@implementation DSPhotoController
@synthesize isNewDoodle, doodleImage;
- (void)viewDidLoad {
[super viewDidLoad];
// Custom backgorund
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_320x480.png"]];
self.view.backgroundColor = background;
}
/**
* Pass additional data to the new controller
*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"confirmUploadSegue"]) {
// Get reference to the destination view controller
DSConfirmController *vc = [segue destinationViewController];
vc.doodleImage = self.doodleImage;
}
}
/**
* Choose image from the library
*/
- (IBAction)chooseFromLibrary:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
self.isNewDoodle = FALSE;
}
}
/**
* Take photo using camera control
*/
- (IBAction)takePhoto:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
[self presentViewController:imagePicker animated:YES completion:nil];
self.isNewDoodle = TRUE;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *) kUTTypeImage]) {
self.doodleImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// Check to make sure the image is new
if (self.isNewDoodle == TRUE) {
UIImageWriteToSavedPhotosAlbum(self.doodleImage, self, @selector(image:finishedSavingWithError:contextInfo:), nil);
}
[self performSegueWithIdentifier:@"confirmUploadSegue" sender:self];
}
}
- (void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Save failed" message:@"Failed to save image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.