UIImagePickerController crashes on iOS4 - iphone

When trying to show the UIImagePickerController I had strange problems with my app crashing on iOS4. Here's the output from log:
malloc: *** error for object 0x550ba20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Setting breakpoints, trying to spy the name of the object 0x550ba20 (with print-object) does not work. Enabling zombie detection also does not work. Here is my code:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
cameraPicker = [[UIImagePickerController alloc] init];
cameraPicker.delegate = self;
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Insert the overlay:
cameraPicker.cameraOverlayView = self.overlay;
self.cameraPicker.delegate = self;
//Hide controls
cameraPicker.showsCameraControls = NO;
cameraPicker.navigationBarHidden = YES;
// Make camera view full screen:
cameraPicker.wantsFullScreenLayout = YES;
cameraPicker.cameraViewTransform = CGAffineTransformScale(self.cameraPicker.cameraViewTransform, 1.0, 1.12412);
[self presentModalViewController:cameraPicker animated:NO];
[cameraPicker release];
Any ideas? Code is executed at the very end of viewDidLoad.

Is cameraPicker a property? You are initializing it first as a local variable and then using it as a property:
cameraPicker.cameraOverlayView = self.overlay;
!!self.!!cameraPicker.delegate = self;
and
cameraPicker.cameraViewTransform = CGAffineTransformScale(!!self.!!cameraPicker.cameraViewTransform, 1.0, 1.12412);

Related

CGAffineTransformInvert: singular matrix in UIImagePickerController with showsCameraControls = NO

I tried this twice with two different apps and I get the same thing. I have a set up a UIImagePIckerController instance as follows:
- (IBAction)addImage:(UIBarButtonItem *)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
if ([mediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
picker.showsCameraControls = NO;
[self presentViewController: picker animated:YES completion:NULL];
}
[..]
}
This was the second. In the first I set up a custom overlay to run the shutter and other functions. Everything runs fine but I keep getting an error on the console:
<Error>: CGAffineTransformInvert: singular matrix.
When I run the app, every time I rotate (or move about which signals a rotate) the device while the camera is up {something happens here}. I tried it on both my iPhone 4 and iPad Mini with the same results. After a lot of digging I found this only happen in the case where
picker.showsCameraControls = NO;
If I put
picker.showsCameraControls = YES;
Then I get no message (though my custom overlay is hidden too). Making sure it wasn't the custom overlay itself I tried leaving that out, and it still gives the error message.
Anybody got any ideas of what I should do about this?
I believe it to be largely benign as Apple's own PhotoPicker sample code generates this warning. Rotation has to do with matrices and while I'm not sure which matrix in particular is getting rotated, it is considered a mathematical violation to perform operations on matrices with a determinant of zero (similar to dividing by zero). Such a matrix is not invertible or 'singular':
http://en.wikipedia.org/wiki/Rotation_matrix
http://en.wikipedia.org/wiki/Determinant
http://en.wikipedia.org/wiki/Singular_matrix#singular

Turn cameraFlash On before takePicture?

Can I programmatically turn on the camera flash on a new iPhone 4 device, before taking a picture with -takePicture?
I'm developing a photo taking app for iOS 4 and want to power on the flash light before the user takes a picture, so they can see the effect of the flash in advance.
The problem seems to be that for the flash light to stay on, you'll need to set the torchMode on and this is only possible in 'video mode' (UIImagePickerControllerCameraCaptureModeVideo), while you can only ask the UIImagePickerController to takePicture when it is on 'photo mode' (UIImagePickerControllerCameraCaptureModePhoto).
So, the following works, but only shows the flash light when taking a picture:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.mediaTypes = [NSArray arrayWithObjects:#"public.image", nil];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self presentModalViewController:picker animated:YES];
And this also works (shows the torch the whole time), but then I cannot take a picture.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self presentModalViewController:picker animated:YES];
When I try the toggleTorch code found here: Turn on torch/flash on iPhone there seems to not be any live video feed in the UIImagePickerController.
Are these UIImagePickerController and AVCaptureSession compatible with each other? or are you supposed to choose for either one or the other?
And does anybody know a workaround to get both the flash mode on (or torchMode) and to be able to takePicture?
Have a look at the WWDC 2010 sessions (specifically 409) where they go into functionality like the one you're looking for.
Essentially you need to move away from UIImagePickerController if you're looking to perform these custom camera functions and move towards AVFoundation classes.

iPhone:Video recording based on timer?

I have implemented the code to do video recording feature. It works fine on 3GS device. I want to restrict the video recording based on some timer setting. Lets say, i want to allow user to do video recording only upto 20 seconds or 35 seconds like that. How can i do that? Can i show the timer kind of control on top of media player while recording the video?
Please suggest me.
Here is my code for video recording:
UIImagePickerController *pickerController =
[[[UIImagePickerController alloc] init] autorelease];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.showsCameraControls = YES;
pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
[self presentModalViewController:pickerController animated:YES];
videoMaximumDuration expects an NSTimeInterval, which is a tpyedef for a float value. So you should pass it a float value. Try it like this:
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.showsCameraControls = YES;
pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; // kUTTypeMovie is actually an NSString.
pickerController.videoMaximumDuration = 30.0f; // limits video length to 30 seconds.
[self presentModalViewController:pickerController animated:YES];
[pickerController release];
UIImagePickerController class has property videoMaximumDuration which works for NSTimeInterval.
By default it's value is set for 10 minutes but you can change it's float value according to your need.
So if you make object of UIImagePickerController class named videoPickerController then you can set timer for capturing video like-
videoPickerController.videoMaximumDuration = 25.0f;

UIImagePickerController exception : "Source type must be UIImagePickerControllerSourceTypeCamera"

what is wrong with this? I really don't understand some important parts for UIImagePickerController....
here's the source:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
Can't I open the photo library?
Any help appreciated!
If you're using the photo library, do you need to set cameraCaptureMode?
Maybe not in your case but when you initalize your UIImagePickerController object, FIRST you need to set your source type before setting any other properties otherwise you get the same error.
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
imagePickerController.cameraCaptureMode =
UIImagePickerControllerCameraCaptureMode.Photo
imagePickerController.cameraDevice = .Front
imagePickerController.showsCameraControls = true;
imagePickerController.navigationBarHidden = false;
imagePickerController.toolbarHidden = false;
imagePickerController.delegate = self
my problem was that i set camera device to .front before setting imagePicker.sourceType = .camera and obviously it caused crash.
so i changed my code from :
imagePicker.cameraDevice = .front
imagePicker.sourceType = .camera
to this :
imagePicker.sourceType = .camera
imagePicker.cameraDevice = .front
and problem solved :)
I had this exact same exception, however I wasn't using an instance of UIImagePickerController control, instead I was showing a web page inside of a UIWebView that had an input w/ HTML Media Access attributes to enable camera access.
The problem is that it seems the UIWebView does not handle the HTML Media Access attributes properly. I noticed that the spec on these attributes changed a few times over time, so while it seemed like valid html and works on safari on the device, it doesn't work on pages rendered using UIWebView.
Bad:
<input type="file" accept="image/*" capture="camera" />
Good:
<input type="file" accept="image/*;capture=camera" />
The exception immediately went away and taking a picture works. This seems to be new to iOS 10 or 11 as it was existing code and didn't blow up in the past.
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
} else {
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
}
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
else {
// do stuff ///....Alert
}

iPhone Developer's Cookbook: ModalAlert Frozen

I've used a recipe from the iPhone Developer's Cookbook called ModalAlert in order to get some text from a user; however, when the alert is shown, the keyboard and buttons are frozen. Here is the code for the modal alert.
+(NSString *) textQueryWith: (NSString *)question prompt: (NSString *)prompt button1: (NSString *)button1 button2:(NSString *) button2
{
// Create alert
CFRunLoopRef currentLoop = CFRunLoopGetCurrent();
ModalAlertDelegate *madelegate = [[ModalAlertDelegate alloc] initWithRunLoop:currentLoop];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:question message:#"\n" delegate:madelegate cancelButtonTitle:button1 otherButtonTitles:button2, nil];
// Build text field
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 260.0f, 30.0f)];
tf.borderStyle = UITextBorderStyleRoundedRect;
tf.tag = TEXT_FIELD_TAG;
tf.placeholder = prompt;
tf.clearButtonMode = UITextFieldViewModeWhileEditing;
tf.keyboardType = UIKeyboardTypeAlphabet;
tf.keyboardAppearance = UIKeyboardAppearanceAlert;
tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
tf.autocorrectionType = UITextAutocorrectionTypeNo;
tf.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
// Show alert and wait for it to finish displaying
[alertView show];
while (CGRectEqualToRect(alertView.bounds, CGRectZero));
// Find the center for the text field and add it
CGRect bounds = alertView.bounds;
tf.center = CGPointMake(bounds.size.width / 2.0f, bounds.size.height / 2.0f - 10.0f);
[alertView addSubview:tf];
[tf release];
// Set the field to first responder and move it into place
[madelegate performSelector:#selector(moveAlert:) withObject:alertView afterDelay: 0.7f];
// Start the run loop
CFRunLoopRun();
// Retrieve the user choices
NSUInteger index = madelegate.index;
NSString *answer = [[madelegate.text copy] autorelease];
if (index == 0) answer = nil; // assumes cancel in position 0
[alertView release];
[madelegate release];
return answer;
}
Thanks!
You should probably check whether a UITextField's userInteractionEnabled property defaults to YES or NO.
// Put the modal alert inside a new thread. This happened to me before, and this is how i fixed it.
- (void)SomeMethod {
[NSThread detachNewThreadSelector:#selector(CheckCurrentPuzzle) toTarget:self withObject:nil]; }
-(void) CheckCurrentPuzzle {
NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init];
// code that should be run in the new thread goes here
if ([gameBoard AreAllCellsFilled]) {
if ([gameBoard FilledWithoutWin]) {
//only show this message once per puzzle
if (![currentPuzzle showedRemovalMessage]) {
NSArray *buttons = [NSArray arrayWithObject:#"Yes"];
if ([ModalAlert ask:#"blah blah blah" withTitle:#"Incomplete Puzzle" withCancel:#"No" withButtons:buttons] == 1) {
NSLog(#"Remove The Incorrect Cells");
[gameBoard RemoveIncorrect];
} else {
[gameSounds.bloop2 play];
}
}
} else {
if ([gameBoard IsBoardComplete]) {
[self performSelectorOnMainThread:#selector(WINNER) withObject:nil waitUntilDone:false];
}
}
}
[pool2 release];
}
-(void) WINNER {
//ladies and gentleman we have a winner
}
I had a problem similar to this in my educational game QPlus. It bugged me because I had the "exact" same code in two related apps, and they did not have the bug. It turned out that the bug was because the selector method was not declared in the header file. I am working in Xcode 4.2.
Details below:
In .m:
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(emailLabelPressed)];
tapRecognizer.numberOfTapsRequired = 1;
[aLabel addGestureRecognizer:tapRecognizer];
[aLabel setUserInteractionEnabled:YES];
And later in the .m:
(void)emailLabelPressed {
//details
}
That works just fine in the simulator, but on an actual device the email interface presented modally will not edit. You can send or save as draft but no editing.
Then add this to the .h file:
(void)emailLabelPressed;
And voila, it works on the device. Of course this was the difference with the related apps - they both had the method declared in the header file. I would classify this as an iOS bug, but being such a novice developer I wouldn't presume to know.
Based on this, you may want to verify that your selector method moveAlert: is declared in your header file.
Enjoy,
Damien