Intermittent crash after UIImagePickerController with camera - ios

We have an app that is working stable, but occasionally users report that they get crashes when they use the function to take a picture with the camera.
The problem is that the crash seems to happen just when UIImagePickerController is closed and the control is returned to the app.
We set the delegate when the pickerController is loaded
- (IBAction)popupShootPhoto:(id)sender {
// Detect if camera is available, otherwise exit
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
return;
}
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:nil];
}
When the app resumes, the photo is normally processed in the callback to the regular delegate method.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
The problem is that we cannot reproduce the problem. All we have to work from are the crash logs that we have available in the organizer from the devices.
This is what the crashing thread typically look like, there are no references to our own code, so we have not much to work from.
Can anyone suggest an approach to resolve or troubleshoot problems like this? The problem has been the same on both iOS 9 and still exists on iOS 10.

Related

UIImagePickerController - picking video in background from photo library

How to continue picking video from photo library in background mode ?
I mean when I press use button from imagePickerController - PhotoLibrary and video is started to get compressing - During this compression process (have attached screenshot) if I press home button(i.e. go to background) and then come to foreground then I got info[UIImagePickerControllerMediaURL] as null, so is it possible that app can continue compressing video in background also and return proper url when come to foreground ?
Screenshot :
My didFinishPickingMediaWithInfo,
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSURL *url = info[UIImagePickerControllerMediaURL];
NSLog(#"url : %#",url);
[picker dismissViewControllerAnimated:YES completion:nil];
}
P.S : If we record video by camera and go to background then it will stop recording there and we can use it after coming foreground.
I have thought of one workaround - UIBackgroundTaskIdentifier but it will not work in every case, if video is big then it have time limit, so looking for any other solution!
Any help will be appreciated! :)
IF we want to pick video continuously in background by UIImagePickerController from photolibrary during video is compressing and user press home button(app go in background) then we have to use UIBackgroundTaskIdentifier for continue execution in background or any other background way which keeps app working in background(less possible thing!). Now, UIBackgroundTaskIdentifier has time limit so we can't pick any size of video, so if we restricted video time duration then we can pick it continuously in background something like,
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.videoMaximumDuration = 60.0;
self.backgroundTask = UIBackgroundTaskInvalid;
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(#"Background handler called. Not running background tasks anymore.");
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}];
[self presentViewController:picker animated:YES completion:NULL];
With UIImagePickerController we can do that much only to pick video in background. If anyone want to pick large video in background then he/she should take look into ALAssetLibrary or Photos framework.

Orientation issue in Landscape mode while opening camera in iOS 7 in iPhone

I am having an app which is only in Landscape Mode. In my app I am opening the Camera from one of my views. It is working well for my iPad but on iPhone it crashes. It is working well in iOS 6 but the app crashes for iOS 7 and only for iPhone.
Below is my code.
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc=[[UIImagePickerController alloc] init ];
ipc.delegate=self;
ipc.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:ipc animated:YES completion:nil];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Desc" message:#"Camera capture is not supported in this device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
How to solve this issue?
It crashes when I select to capture from camera. It doesn't crash from the above code but after that it crashes with below error.
I am getting this error:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
And my app crashes.
My orientation code on this view.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ;
}
I am also getting same problem previously. I followed the steps. Please try this and let me know if your facing same problem.
check mark
Step 1:
check in appdelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
step 2: In your view controller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
Step 3: your view controller
-(IBAction)TakePhoto:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];//add to view as per requirement
}
else
{
UIAlertView *noCam = [[UIAlertView alloc] initWithTitle:#"Notification" message:#"There is No Camera Fecility" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[noCam show];
}
}
Does the crash occur on launching the UIImagePickerController or after taking an image with the camera? I tried out your code on an iPod running iOS7 and it works fine. The issue could be somewhere else. I've seen crashes happening with the UIImagePickerController due to memory usage so that could be something for you to check. Also while we're at it, presentModalViewController:animated: is deprecated since iOS6.0. You need to use presentViewController:animated:completion: instead. Also seeing the release statement for your UIAlertView, it looks like you're not using ARC so memory usage is definitely something I would look into. Hope this helps.EDIT: From the UIImagePickerController documentationImportant: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.
Try this code, it works on my old app.
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
May be you want to check this: GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation
I found my solution from the link iOS7 iPad Landscape only app, using UIImagePickerController.
It worked for me like a charm.
Hope it help someone else also.
Thanks for your help people.
I had inherited the UIImagePickerController, and override the tow methods to supported landscape (or you can make a category):
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate
{
return YES;
}
And add the Portrait (bottom home button), Landscape (left home button), Landscape (right home button) in Supported interface orientations(iPad).
Here, must add the Portrait (bottom home button) value, because the UIImagePickerController just supports portrait mode only, so we need to add the portrait mode, otherwise it will raise an exception.

Why are my images being set to UIImageOrientationRight when taken on an iPod running iOS 6 in portrait mode?

My setup is this for testing is this:
iPod Touch 4th Generation (non-autofocus camera)
Running iOS 6.1.6 (latest for this model)
App is built with latest Xcode 5.1.1 and iOS 7.1, but with backwards compatibility to run on iOS 6 devices
Whenever I take a portrait picture with this device using UIImagePickerController, my returning image has an orientation of UIImageOrientationRight. Shouldn't it be giving me UIImageOrientationUp?
Here is the call I use to open the camera:
- (IBAction)goToCamera
{
UIImagePickerController *mypicker = [[UIImagePickerController alloc] init];
mypicker.delegate = self;
mypicker.allowsEditing = NO;
mypicker.sourceType = UIImagePickerControllerSourceTypeCamera;
mypicker.showsCameraControls = YES;
mypicker.wantsFullScreenLayout = YES;
[self presentViewController:mypicker animated:YES completion:nil];
}
Here is the return delegate call:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImage = info[UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(#"%d", pickedImage.imageOrientation);
}
The NSLog is always showing UIImageOrientationRight, even when I take the picture in portrait. Why?
Image Orientation is not the same as Interface Orientation.
As you've discovered, the camera's native orientation is landscape (makes sense, that's the "expected" orientation of traditional cameras) Rather than go to the expense of actually rotating images taken in other orientations, iOS just changes the orientation tag so that it will get displayed correctly.

give ios simulator permission to access photo albums [duplicate]

This question already has answers here:
iOS stopped asking user for Photo Library Permission
(6 answers)
Closed 8 years ago.
I've an iphone app where the user is able to upload photos. During test on ios simulator, everytime I click the "upload image" button, the simulator pops up an alert that says I should give the app permission to access photo albums.
The problem is that the simulator never asked me before if I want to give it access or not. And when I go to privacy settings on the simulator -> photos, I do no see the app to toggle it ON!
I tried resetting content & settings of the simulator, but that didn't solve the problem.
I'm using xCode 5.0.2
Simulator 7.0 iOS 6.1 simulator component
did you check Settings->Privacy->Photos? you should allow your app have full access here.
add following code to somewhere
UIImagePickerController* picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:Nil];
remember to add this function to handle picked image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
try this then to see what happened on your machine.
I found the problem
There is code
if (status != ALAuthorizationStatusAuthorized) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Please give the app access to photo album" delegate:nil cancelButtonTitle:#"Close" otherButtonTitles:nil, nil];
[alert show]; }
I changed:
if (status != ALAuthorizationStatusAuthorized) {
to
if (status == ALAuthorizationStatusDenied) {
Then it worked and asked me for permission, accepted it, and everything is ok now
Thanks everyone

ios UIImagePickerController delay switching to front camera in the first time

I have implemented to launch UIImagePickerController to capture picture. At the first time, rear camera appear fast, then I switch to front camera, it responses very slowly. It seems to take me nearly 15 seconds. I don't know why initing front camera so slow.
Here my code
UIImagePickerController * _picker = nil;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_picker = [[[UIImagePickerController alloc] init] autorelease];
_picker.delegate = self;
_picker.allowsEditing = NO;
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:_picker animated:YES];
}
UPDATE: My device is iPad 2 (iOS 7.0), I also test Facebook app on my device, it responses immediately when I switch to front camera. When I test my app on Ipad mini (iOS 6.1.3), it works very well, this problem doesn't happen. Can someone figure me out, it's little missing when initialize UIImagePickerController, I suppose.
UPDATE 2: I wrote an another very simple project. It launches an UIImagePickerController immediately on viewDidLoad of the rootViewController and it works well, UIImagePickerController responses instantly when I switch to front camera. Does anyone have idea for it?
Do this on new thread would cancel the delay on open url. I bet it is the same delay.
Note: Not yet tested on camera.
[NSThread detachNewThreadSelector:#selector(openbrowser_in_background:) toTarget:self withObject:Object];
- (void)openbrowser_in_background:(NSString *)url
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
}
And you might like to change the openURL to
[self presentModalViewController:_picker animated:YES];

Resources