UIImagePickerController causing crash - ios

I'm using ios 8.4. When debugging an app, and I present a UIImagePickerController, xcode loses connection with the iphone. This wasn't a problem before.
Sometimes it will bring up the image picker... but then when I save an image, there'll be a crash.
Is anyone else experiencing this? How to fix?
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.editing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls=YES;
[self presentViewController:imagePickerController animated:YES completion:nil];

try this code
- (IBAction)galleryButtonPressed:(id)sender
{
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.allowsEditing = YES;
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:NULL];
}
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:NULL];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil)
image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Do something with the image
[self.imageView setImage:image];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:NO completion:nil];
}

Related

Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

In iOS 8, When i click to open the camera from my ipad mini it gives warning
"Snapshotting a view that has not been rendered results in an empty snapshot"
I am using the below code to open camera from my device.
- (IBAction)takePhotograph:(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.cmdTakePhotograph setImage:chosenImage forState:UIControlStateNormal];
[picker dismissViewControllerAnimated:YES completion:NULL];
imageTaken = 1;
Compress = 1;
self.lblErrMsg.hidden = YES;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Please suggest me solution to remove this warning.
Hope this helps you.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)])
{
[imagePicker setShowsCameraControls:NO];
[self presentViewController:imagePicker animated:YES completion:^{
[imagePicker setShowsCameraControls:YES];
}];
}
else
{
[imagePicker setShowsCameraControls:YES];
[self presentModalViewController:imagePicker animated:YES];
}

ImagePickerController for iOS

I am trying to select a picture from the device's photo library.
This is my code so far. I am following a tutorial and that should work, but I am getting an error :
"Use of undeclared identifier info", on the second method, line 3.
What am I doing wrong?
- (IBAction)selectPicturePressed:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
UIImage *chosenImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
self.imgToUpload.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Change info to editInfo will resolve it.

iOS 8 UIImagePickerController allowsEditing crash

Have anyone noticed that if you use UIImagePickerController and allowsEditing = YES in iOS 8, your app will crash after the editing view being presented.
*** -[PUUIImageViewController traitCollection]: message sent to deallocated instance 0x7f8d714ab5e0
I can find few information about this PUUIImageViewController. It seems like a new class in iOS 8.
I've spent 2 days on my code and started thinking this may be a bug in iOS 8.
Any ideas?
Here's my code for opening the UIImagePickerController
- (void)picButtonPressed:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
self.imagePickerController.allowsEditing = YES;
self.imagePickerController.mediaTypes = #[(NSString *)kUTTypeImage];
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.imagePickerController animated:YES completion:^{
}];
}
}
As for UIImagePickerController's delegate:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:^{}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerEditedImage];
[self dismissViewControllerAnimated:YES completion:^{}];
}
The app crashes after the controller dismiss UIImagePickerController.

How to save the selected image in UIImagePicker controller?

I can take a photo and it shows in imageviewn but as soon as I leave detailviewn and go to back to detailviewn its disappear. How should the image always be saved?
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[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];
}
Check your IBOutlet Connection in xib file and You have to save the image taken in documents directory of your application , unless you cannot view the selected image

ioS7: Capture multiple images from camera and store in array

guys.
I'm trying to capture multiple images from the camera in iOS7, when I capture the first image and click in in "Use Photo", then it's store the image in a array in didFinishPickingMediaWithInfo. When the camera appear again, I see the last image in background but I can't see the camera movement. I know the camera is enabled, because it's searching faces. The code is below:
- (IBAction)openTour:(id)sender
{
_counter=0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
imagePicker = nil;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image= [info objectForKey:UIImagePickerControllerEditedImage];
[ _imageArray addObject:image ];
_counter++;
if ( _counter<5 )
{
[self dismissViewControllerAnimated:NO completion:nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:nil];
imagePicker = nil;
}
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Does anyone know what is happening?
Thanks in advance!
Set showsCameraControls = NO;
Use cameraOverlayView property.
In the action of your camera button call takePicture method.
Keep adding UIImage objects received by the method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

Resources