ABPeoplePickerNavigationController and UIImagePickerController not displaying correctly on ipad iOS7 - ios

When I try use "ABPeoplePickerNavigationController" or "UIImagePickerController", in most cases it won't load up correctly. It will show part of the screen (transparent) starting in the middle of the screen in iOS 7 (ipad) for both simulator and device (screenshot below). In iOS 8 everything works correctly.
This is the code I use for ABPeoplePickerNavigationController:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
self.preserveCurrentEntity = YES;
[self presentViewController:picker animated:NO completion:nil];
UIImagePickerController will break just for picking videos, but work for everything else, this is the code I use:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
switch (buttonIndex) {
case ImagePickerModeCamera:
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case ImagePickerModeAlbum:
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
default:
break;
}
imagePicker.delegate = self;
NSMutableArray *mediaType = [[NSMutableArray alloc] init];
switch (self.actionSheetType) {
case ActionSheetTypeImage:
[mediaType addObject:(NSString*)kUTTypeImage];
break;
case ActionSheetTypeVideo: {
[mediaType addObject:(NSString*)kUTTypeMovie];
[mediaType addObject:(NSString*)kUTTypeVideo];
imagePicker.allowsEditing =NO;
}
break;
default:
break;
}
imagePicker.mediaTypes = mediaType;
[self presentViewController:imagePicker animated:NO completion:nil];
This is what happens in iOS7 when loading ABPeoplePickerNavigationController:
This is what happens in iOS8 when loading ABPeoplePickerNavigationController:
What is the solution to fix this?

Looks like I found the solution to my problem.
I have a root view controller that has two xibs, one for iPad and one for iPhone. It seems my iPad one was causing the trouble even though they were very similar (just one was larger). I couldn't figure out why.
I just use the iPhone one now and make sure it resizes correctly on iPad and everything is working correctly.

I have the same problem like you, but after wasting some time I got some post, that what may be the reason in your case.
iPhone Library does not work on the iOS Simulator in special case of picking Vedio
Referred Post for my solution. and worked for me.
Update on it, if you still facing problem, I can post my code to help you.
HTH, Enjoy Coding !!

Related

How to Pick/browse audio files from device library like photo library?

I am building an app in which user can pick(from library) or capture(record) image/video/audio.
I have already implemented for video and image media and recoding audio file but while accessing audio from library its crashing on below line. Its working fine when I try to acsess image and video file from library.
I think this is happening because of audio file are not storeded in photoLibrary, if so can anyone please tell me how can I accsess/open only audio files from device so user can have options to choose.
// below is the code I'm using for selecting media (image/video/audio)
- (void)selectingMediaFromLibraryOfType:(MEDIAUPLOADTYPE)mediaType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
switch (mediaType) {
case mediaUploadTpeAudio:
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMP3, nil]; //crashing on this line
break;
case mediaUploadTpeImage:
break;
case mediaUploadTpeVideo:
picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
break;
default:
break;
}
[self presentViewController:picker animated:YES completion:NULL];
}
I have done same for image and video and it's working.
Also I want to know where files are store when you transfer/download audio file from ios to ios.
Media picker for audio is different than images and videos. You have to use MPMediaPickerController class. It functions same as UIImagePickerController class.
and implement MPMediaPickerControllerDelegate to get the selected files.

UIImagepicker Controller not working on touch but only on swpie

In my code , uiimagepickerviewcontroll is not selecting image on touch , it selects image either on swipe on the image or very long press.
I've not added any special code below is the code I've used.
self.imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePickerController.allowsEditing = NO;
_imagePickerController.delegate = self;
[self.navigationController pushViewController:self.imagePickerController animated:YES];
if any one have any solution , please help me.
Thanks.
Hi, try this way, working always correct for me:
UIImagePickerController *imagePicker = [UIImagePickerController new];
imagePicker.delegate = self;
imagePicker.mediaTypes = #[(NSString*) kUTTypeImage];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum ;
_libraryImagePickerController = imagePicker;
Hope it helps :)
I don't know why this issue came, but I found only 1 solution, created a new project and copied whole code to the new one.
Issue was automatically resolved.

iOS 7 UIImagePicker preview black screen

When i try to load camera from my code, camera preview is black. If I wait for 10-20 seconds it will show real camera preview. I found several questions and some of them suggest that running some other code in background should be the reason for this. However I don't have any code running in background.
How should I fix this?
This is my code where I run camera
UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:photoPicker animated:YES completion:NULL];
About 5 months ago my team discovered a memory leak with UIImageViewController in iOS7. Each instantiation slowed down the app exponentially (i.e. first alloc-init had a 1 second delay, second had a 2 second delay, third had a 5 second delay). Eventually, we were having 30-60 delays (similar to what you're experiencing).
We resolved the issue by subclassing UIImagePickerController and making it a Singleton. That way it was only ever initialized once. Now our delay is minimal and we avoid the leak. If subclassing isn't an option, try a class property in your viewController and just lazy load it like so.
-(UIImagePickerController *)imagePicker{
if(!_imagePicker){
_imagePicker = [[UIImagePickerController alloc]init];
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
return _imagePicker;
}
Then you can just call it later like:
[self presentViewController:self.imagePicker animated:YES completion:nil];
Had this myself - it happens if something is running on the main dispatch thread - are you resizing images by any chance?
It puts the preview onto the main thread and if something is using it, you get a black screen. It's a bug and the workaround is to either take over the main thread or to disable the photo picker until the queue is free
This Should work for you:
- (void)cameraViewPickerController:(UIImagePickerController *)picker
{
[self startCameraControllerFromViewController: picker
usingDelegate: self];
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
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 *) kUTTypeImage, (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;
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}

UiImagePickerController - more than one photo

Iphone app, IOS 5 and up.
There are similar questions to this one on SO but I haven't encountered this exact scenario so I'll ask. I'm editing an existing app that allows lets you take a photo which it resizes and sends to a web service.
I need to add the ability to take 3 photos, resize each and send to the same service. I thought it would be just a matter of repeating what was already in the app but it uses the UIImagePickerController which apparently only allows one photo per use.
So the way it works is that there's a 'Take Photo' button which calls the method below. Once that photo is taken another button appears that says 'Take another photo' (I added this button) and I have it calling the same method but it is just copying over the previous photo, which is to be expected really. How should I best alter this to accommodate 3 photos?
This is the takephoto method that I'm calling.
- (IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
check this https://developer.apple.com/library/ios/samplecode/photopicker/Introduction/Intro.html
, check the take photo part of this demo project.
Eventually figured out how to do this. I added a tag to the button calling the method, through IB.
Then in the takephoto method I assigned the imagePickerController a tag based on the tag of the button that tapped. Like this:
- (IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if([sender tag] == 2)
{
imagePickerController.view.tag = 2;
}
//And so on...
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
Then in the ImagePickerController didFinishedPickingMediaWithInfo method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if(picker.view.tag == 2)
{
//Do stuff here
}
}
So, I'll probably have to create three different buttons for each of the three possible photos, I'm sure there's a better way than that but it should work.

<Error>: CGAffineTransformInvert: singular matrix. in UIimagepickercontroller [duplicate]

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

Resources