UIImagePickerController disable iPhone 4S face detection (iOS 5.1) - ios

I am currently developing an iPhone app that makes use of a UIImagePickerController with a custom overlay to take photos.
Unfortunately I do not have direct access to an iPhone 4S but several testers have reported that the camera picker is drawing a green border around faces exactly like this: http://cdn.iphonehacks.com/wp-content/uploads/2012/03/camera_faces.jpg
Due to the nature of this app this is not desirable.
A thorough search of the UIImagePickerController docs didn't turn up anything and similarly everything I could find on here relating to face detection was providing instructions in how to use a CIDetector or similar.
How can I disable face detection in my UIImagePickerController?
Here is my initialisation code for the UIImagePickerController:
UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];
[cameraPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[cameraPicker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
if ([UIImagePickerController isFlashAvailableForCameraDevice:cameraPicker.cameraDevice]){
[cameraPicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
}
[cameraPicker setShowsCameraControls:NO];
[cameraPicker setCameraOverlayView:cameraOverlayView];
cameraPicker.delegate = self;
[self presentModalViewController:cameraPicker animated:YES];

Try This -->
Lets Say We have one UIViewController named as - RecordVideoViewController
Implementation of -- RecordVideoViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <AssetsLibrary/AssetsLibrary.h>
#interface RecordVideoViewController : UIViewController
- (IBAction)recordAndPlay:(id)sender;
-(BOOL)startCameraControllerFromViewController:(UIViewController*)controllerusingDelegate:
(id)delegate;
-(void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error
contextInfo(void*)contextInfo;
#end
Implementation of -- RecordVideoViewController.m
- (IBAction)recordAndPlay:(id)sender {
[self startCameraControllerFromViewController:self usingDelegate:self];
}
-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
usingDelegate:(id )delegate
{
// 1 - Validattions
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ==
NO)
|| (delegate == nil)
|| (controller == nil)) {
return NO;
}
// 2 - Get image picker
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
// 3 - Display image picker
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *)info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
// Handle a movie capture
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) ==
kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum(moviePath,
self,#selector(video:didFinishSavingWithError:contextInfo:),nil);
}
}
}
-(void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:
(void*)contextInfo {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Video Saving
Failed"
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Video Saved" message:#"Saved To
Photo Album" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
Implement This code it, i hope this will help you .

Check out this post. There are some hints here, but still can't find much info outside of Apple's docs on this API.
Proper usage of CIDetectorTracking

Related

iOS Camera not opening

I created an app a couple of years ago and had it working no problem at all. I've been asked to resurrect it and have stumbled apron a problem. When selecting a button to open up the camera and/or photo library it comes up with this message when choosing either option:
Warning: Attempt to present <UIImagePickerController: 0x100a13400> on :<ViewController: 0x100843a00> which is already presenting <UIAlertController:0x1001e8d40>`
Im wondering has there been changes between iOS's that i need to amend my code because of? Here is what I currently have:
- (IBAction)pickImage {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(status == AVAuthorizationStatusAuthorized) { // authorized
}
else if(status == AVAuthorizationStatusDenied){ // denied
}
else if(status == AVAuthorizationStatusRestricted){ // restricted
}
else if(status == AVAuthorizationStatusNotDetermined){ // not determined
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){ // Access has been granted ..do something
} else { // Access denied ..do something
}
}];
}
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Pick Image"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"from Camera", #"from Library", nil] ;
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePickerController setDelegate:self];
[self presentModalViewController:imagePickerController animated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:#"Your device has no camera."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
else if (buttonIndex == 1) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
[self presentModalViewController:imagePickerController animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[imageView setImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
[self dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
Many Thanks for your help.
Not able to replicate that error message with that code, however, you can try replacing your UIActionSheet and UIAlertView with a UIAlertController.
Both of these are deprecated as of iOS 8.0, and have been replaced with the UIAlertController.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/
You can set the preferred style attribute to "UIAlertControllerStyleAlert" or "UIAlertControllerStyleActionSheet".

Saving pictures to parse

My project will save data to parse and while I can pick an image from my library I cannot open the camera. I found a tutorial to do this but it is not compatible with my code. The link to the tutorial is here: Tutorial . I am using .storyboard and the tutorial is .xib, I do not know if this will change anything.
my .m file is here:
#import "NewRecipeViewController.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import <Parse/Parse.h>
#import "MBProgressHUD.h"
#interface NewRecipeViewController ()
- (IBAction)save:(id)sender;
- (IBAction)cancel:(id)sender;
#property (weak, nonatomic) IBOutlet UIImageView *recipeImageView;
#property (weak, nonatomic) IBOutlet UITextField *nameTextField;
#property (weak, nonatomic) IBOutlet UITextField *prepTimeTextField;
#property (weak, nonatomic) IBOutlet UITextField *ingredientsTextField;
#end
#implementation NewRecipeViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_nameTextField.delegate = self;
_prepTimeTextField.delegate = self;
_ingredientsTextField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
[self showPhotoLibary];
}
}
- (void)showPhotoLibary
{
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)) {
return;
}
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// Displays saved pictures from the Camera Roll album.
mediaUI.mediaTypes = #[(NSString*)kUTTypeImage];
// Hides the controls for moving & scaling pictures
mediaUI.allowsEditing = NO;
mediaUI.delegate = self;
[self.navigationController presentModalViewController: mediaUI animated: YES];
}
- (IBAction)save:(id)sender {
// Create PFObject with recipe information
PFObject *recipe = [PFObject objectWithClassName:#"Recipe"];
[recipe setObject:_nameTextField.text forKey:#"name"];
[recipe setObject:_prepTimeTextField.text forKey:#"prepTime"];
NSArray *ingredients = [_ingredientsTextField.text componentsSeparatedByString: #","];
[recipe setObject:ingredients forKey:#"ingredients"];
// Recipe image
NSData *imageData = UIImageJPEGRepresentation(_recipeImageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:#"%#.png", _nameTextField.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[recipe setObject:imageFile forKey:#"imageFile"];
// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Uploading";
[hud show:YES];
// Upload recipe to Parse
[recipe saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
[hud hide:YES];
if (!error) {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Upload Complete" message:#"Successfully saved the recipe" delegate:Nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
// Notify table view to reload the recipes from Parse cloud
[[NSNotificationCenter defaultCenter] postNotificationName:#"refreshTable" object:self];
// Dismiss the controller
[self dismissViewControllerAnimated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
}
- (IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidUnload {
[self setRecipeImageView:nil];
[self setNameTextField:nil];
[self setPrepTimeTextField:nil];
[self setIngredientsTextField:nil];
[super viewDidUnload];
}
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
UIImage *originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
self.recipeImageView.image = originalImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Textfield delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (IBAction)takephoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectphoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#end
Any help is appreciated.
Take a look at Apple's provided sample project (especially APLViewController.m)
https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196
You'll see them do the following 4 steps. You are only doing the last half of step one, without first verifying if that source type is even available.
From the UIImagePickerController Class Reference:
To use an image picker controller containing its default controls, perform these steps:
Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the “UIImagePickerControllerSourceType” enumeration.
Check which media types are available, for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.
Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the mediaTypes property.
Present the user interface. On iPhone or iPod touch, do this modally (full-screen) by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller.

Save images to photo library ONLY if they are taken by camera and not if chosen from photo library

I have a photo picker in my app that asks the user if they want to take a picture or choose one from the photo library. Upon completion of their choice I set an image view to their chosen image and I want to save the image they just set only if it was taken from the camera and not if it was just an edited version of a photo they already have. The last method listed here is the one in which I wish to save the photo.
- (IBAction)startPicker:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIActionSheet *picChoice = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Camera", #"Photo Library", nil];
[picChoice showFromRect:[(UIButton *)sender frame] inView:self.view animated:YES];
} else {
UIActionSheet *picChoice = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Photo Library", nil];
[picChoice showFromRect:[(UIButton *)sender frame] inView:self.view animated:YES];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:#"Camera"]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:#"Photo Library"]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
} else {
return;
}
[self presentViewController:imagePicker animated:YES completion:^{
}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:editedImage.CGImage orientation:(ALAssetOrientation)editedImage.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error )
{
NSLog(#"IMAGE SAVED TO PHOTO ALBUM");
[library assetForURL:assetURL resultBlock:^(ALAsset *asset )
{
NSLog(#"we have our ALAsset!");
}
failureBlock:^(NSError *error )
{
NSLog(#"Error loading asset");
}];
}];
Simply check the sourceType:
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
// save to library
}
Do this in your imagePickerController:didFinishPickingMediaWithInfo: method.

UIImagePickerController camera type returning black image

I am struggling with UIImagePickerController as when i open camera and take image it show black screen in IOS 7 as this is working fine in ios 6, i have tried some other links what says but its not working, please help me with this...
and i am getting this error too
<Error>: CGAffineTransformInvert: singular matrix.
and now i got something ..
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
when i just click on take image button
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
dispatch_async(dispatch_get_main_queue(), ^{
if (buttonIndex == 0) {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
// This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.
if(authStatus == AVAuthorizationStatusRestricted){
NSLog(#"Restricted");
}
// The user has explicitly denied permission for media capture.
else if(authStatus == AVAuthorizationStatusDenied){
NSLog(#"Denied");
}
// The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.
else if(authStatus == AVAuthorizationStatusAuthorized){
NSLog(#"Authorized");
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:imagePickerCamera animated:YES completion:^{}];
});
} else {
NSString *errorString = [NSString stringWithFormat:#"This device does not support this feature."];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
// Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
else if(authStatus == AVAuthorizationStatusNotDetermined){
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
if(granted){
NSLog(#"Granted access to %#", mediaType);
}
else {
NSLog(#"Not granted access to %#", mediaType);
}
}];
}
else {
NSLog(#"Unknown authorization status");
}
}
else {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
dispatch_async(dispatch_get_main_queue(), ^{
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.mediaTypes = #[(NSString *) kUTTypeImage];
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePickerCamera animated:YES completion:nil];
});
} else {
NSString *errorString = [NSString stringWithFormat:#"This device does not support this feature."];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
} else if (buttonIndex == 1) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
imagePickerAlbum.delegate = self;
imagePickerAlbum.mediaTypes = #[(NSString *) kUTTypeImage];
imagePickerAlbum.allowsEditing = YES;
imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerAlbum animated:YES completion:nil];
} else {
NSString *errorString = [NSString stringWithFormat:#"This device does not support this feature."];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
});
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
_upLoadimage = info[UIImagePickerControllerEditedImage];
}
I had the same problem with camera. My screen to modify or editing camera image was appearing black. The log showed me same error (CGAffineTransformInvert xx ). I did a lot of checks to determine or know where is the error.
In my application I use the component SVProgessHUD to show alerts and messages. Commenting lines with this use corrects the problem. I have updated to the last version of the component (1.0) and the error CGAffineTransformInvert disappears.

UIImagePickerController - [picker dismissViewControllerAnimated:YES completion:Nil]; Error

I have been trying this for the past 2 days and I am not able to figure out the answer. I have searched all over and I haven't found the answer.
The question is I have a button which brings up the camera in my app(to take photos only). The camera opens up, but when i take a picture and click on "USE"(which is displayed at the bottom right) its crashing. Also, when the camera opens up, before taking a picture when I click "Cancel" it again crashes.
I tried using breakpoints and found out that, When I click on the "USE" button, it crashes in this line
[picker dismissViewControllerAnimated:YES completion:Nil]
I'm testing it in my iPad (iOS6).
Here is the Button Code here :
-(IBAction)getAlbum:(id)sender {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSArray *media = [UIImagePickerController
availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
if ([media containsObject:(NSString*)kUTTypeImage] == YES) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
[picker setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeImage]];
picker.delegate = self;
//[self presentModalViewController:picker animated:YES]; //Since [Modal](http://stackoverflow.com/questions/12445190/dismissmodalviewcontrolleranimated-deprecated) has been removed
[self presentViewController:picker animated:YES completion:Nil];
//[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Unsupported!"
message:#"Camera does not support photo capturing."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Unavailable!"
message:#"This device does not have a camera."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
imagePickerController Method here:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(#"Media Info: %#", info);
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
UIImage *photoTaken = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//Save Photo to library only if it wasnt already saved i.e. its just been taken
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(photoTaken, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
selectedLogoImg.image=photoTaken; //selectedLogoImg is the imageView
[self.clipartItemView addSubview:selectedLogoImg]; // To detect touch and move it I place it as a subview of self.clipartItemView
}
//[picker dismissModalViewControllerAnimated:YES];
[picker dismissViewControllerAnimated:YES completion:Nil]
//[picker release];
//[picker dismissViewControllerAnimated:YES completion:^{
// NSLog(#"Dismiss completed");
//}];
}
didFinishSavingWithError Code Here:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
UIAlertView *alert;
//NSLog(#"Image:%#", image);
if (error) {
alert = [[UIAlertView alloc] initWithTitle:#"Error!"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
imagePickerControllerDidCancel Code Here:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
//[picker dismissModalViewControllerAnimated:YES];
/*[picker dismissViewControllerAnimated:YES completion:^{
[self.view sendSubviewToBack:cardGalleryView];
}];*/
[picker dismissViewControllerAnimated:YES completion:Nil];
}
You should send the dismissViewControllerAnimated:completion: message to the view controller, not the picker. Try:
[self dismissViewControllerAnimated:YES completion:nil];
The above method is only for iOS 6. You need to use [self dismissModalViewControllerAnimated:YES] for iOS 5 and below.
Take a look at the description of the method in the documentation:
Dismisses the view controller that was presented by the receiver.
The presenting view controller is responsible for dismissing the view
controller it presented. If you call this method on the presented view
controller itself, however, it automatically forwards the message to
the presenting view controller
This problem is due to your UIImagePickerController *picker object . ViewController isn't able to identify your picker object reference out of the getAlbum method scope.
1.> you can create UIImagePickerController object in your .h file
#interface yourViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate>
{
UIImagePickerController *picker;
UIPopoverController *popover;
}
and in .m file you just use it inside getAlbum IBAction method
-(IBAction)getAlbum:(id)sender {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSArray *media = [UIImagePickerController
availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
if ([media containsObject:(NSString*)kUTTypeImage] == YES) {
UIButton *btn=(UIButton *)sender;
if ([popover isPopoverVisible])
{
[popover dismissPopoverAnimated:YES];
popover=nil;
}
picker = [[UIImagePickerController alloc]init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[picker setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeImage]];
picker.delegate = self;
popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:CGRectMake(btn.frame.size.width,btn.frame.size.height/2,1,1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Unsupported!"
message:#"Camera does not support photo capturing."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Unavailable!"
message:#"This device does not have a camera."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)myimage editingInfo:(NSDictionary *)editingInfo
{
myimage = [myimage fixOrientation];
[picker dismissModalViewControllerAnimated:YES];
[popover dismissPopoverAnimated:YES];
}
I hope it helps you to better understand.

Resources