MPMediaPickerController very slow on iPad ios7 - ios

I am trying to display a MPMediaPickerController in a popover on iOS7+ and it is VERY slow. It takes about 4 seconds from the first NSLog to the second NSLog. I have tried retaining the picker but this makes no difference. Any ideas would be greatly appreciated.
- (void) showMediaPickerControllerWithArrowDirection:(UIPopoverArrowDirection)arrow_direction
{
MPMediaPickerController *self.picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
self.picker.modalPresentationStyle = UIModalPresentationPopover;
self.picker.delegate = self;
self.picker.allowsPickingMultipleItems = YES;
UIPopoverPresentationController *popPresenter = self.picker.popoverPresentationController;
popPresenter.sourceView = self.view;
popPresenter.sourceRect = self.view.bounds;
popPresenter.permittedArrowDirections = arrow_direction;
NSLog(#"____________________________ about to launch picker ");
[self.viewController presentViewController:self.picker animated:YES completion:^{
NSLog(#"____________________________ picker launched ");
}];
}

Related

How to update the the style for frame size in UIDocumentPickerViewController

In my app, the frame size of my UIDocumentPickerViewController always full screen as the following picture and the following code. However, I find there is a different frame size for the UIDocumentPickerViewController but I don't know how to get the effect as the second picture. Does anyone know how to get the effect?
https://drive.google.com/file/d/1_q_kfIIYA0d0KcT7NyPpFb6Q1vymU-lb/view?usp=sharing
- (void)btnPressDown {
NSLog(#"Press Down QQ");
[self showDocumentPickerInMode:UIDocumentPickerModeImport];
}
- (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode {
NSLog(#"showDocumentPickerInMode QQ");
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:#[#"public.data"] inMode:mode];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
https://drive.google.com/file/d/177W-O0eJmePhLfS8ifGlw9n3jj26FDn9/view?usp=sharing
You need to set presentation style. The presentation style determines how a modally presented view controller is displayed onscreen.
"picker.modalPresentationStyle = UIModalPresentationFormSheet;"
- (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode {
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:#[#"public.data"] inMode:mode];
picker.modalPresentationStyle = UIModalPresentationFormSheet;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
Thats it :)

iOS, PopOverPresentationController issue, .xib

I have a NavigationController, another controller was pushed on its stack: BNRDetailsViewController. Now, inside BNRDetailsViewController I am trying to show a popover window when pressing on a toolbar button, that would present me with UIImagePickerController (only on iPad devices). So, I tried to follow the following stackoverflow thread:
UIPopoverPresentationController on iOS 8 iPhone
But no success. If I just use their code I get an error that says, that pushing navigationController is not supported. If I try to push the newly created UIPopoverPresentationController like this: [self.navigationController pushViewController:self.imagePickerPopover animated:YES]; it crashes because UIPopoverPresentationController is not of type UIViewController, so, I guess, I can not just push it on the stack.
What would you suggest to do in this particular case?
Here is the code which I have right now that is triggered when the toolbar button is pressed:
- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// If the device have camera, take a picture, otherwise,
// just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
// Place image picker on the screen
//[self presentViewController:imagePicker animated:YES completion:NULL];
// Place image picker on the screen
// Check for iPad device before instantiating the popover controller
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Create a new popover controller that will display the imagePicker
_imagePickerPopover = [[UIPopoverPresentationController alloc] initWithPresentedViewController:imagePicker presentingViewController:self];
imagePicker.preferredContentSize = CGSizeMake(280, 200);
_imagePickerPopover.delegate = self;
_imagePickerPopover.sourceView = self.view;
CGRect frame = [[sender valueForKey:#"view"] frame];
frame.origin.y = frame.origin.y + 20;
_imagePickerPopover.sourceRect = frame;
// [self.navigationController pushViewController:self.imagePickerPopover animated:YES];
}
}
Here is the code, based on your code, that will get the popover to display on the iPad.
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
imagePicker.modalPresentationStyle = UIModalPresentationPopover;
imagePicker.preferredContentSize = CGSizeMake(280, 200);
CGRect frame = [[sender valueForKey:#"view"] frame];
frame.origin.y = frame.origin.y + 20;
UIPopoverPresentationController *popoverController =
imagePicker.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = frame;
[self.navigationController presentViewController:imagePicker
animated:YES completion:nil];
}

Can't present imagepicker immediately

I have a Tab bar controller, when I tap the third tab bar button I present a UIViewcontroller. In the viewWillAppear of this vc I'm presenting a UIImagepickerController that works fine. The problem is I can't display it on the screen immediately when I open the view. First the vc shows up and after 0.4-0.5 sec the image picker. So I would like to present the image picker first and present the vc after the user took an image. I tried to call the picker from viewDidLoad and viewWillAppear too, but nothing changed.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (imagePickerWasPresented == NO)
{
imagePickerWasPresented = YES;
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
Am I calling it in a wrong place?
I had the same problem - instead of calling the VC and then the UIImagePicker, call the UIImagePicker directly.
When you are done taking a picture/video:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {}
you will go to this standard delegate method, call the VC from here. This way you will immediately go to the ImagePicker and only have a transition would you choose to do something with the taken content afterwards which is less frustrating/ugly.
No, your calling it in an okay place, that's just how iOS does it; if you present multiple modals on top of each other, one gets presented after the other, including the animation. A solution that would work for your problem is to present a UINavigationController instead of your UIViewController. Set the navigation controller up to have ViewController as the root viewcontroller, but also push your imagepickercontroller onto the stack. Present this navigationcontroller and it should go right to your imagepickercontroller. Otherwise, try presenting both uiviewcontroller and imagepickercontroller with animation set to NO and see if that works.
try this to see how close that gets you then adapt to your needs. when i gave it a quick test it seemed to do what you were asking.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
UIViewController * vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
UINavigationController * navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:vc animated:NO];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:navigationController, nil];
tabBarController.viewControllers = controllers;
tabBarController.delegate = self;
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
[vc presentViewController:imagePicker animated:NO completion:nil];
return YES;
}
UIImage as a PopOver
Gallery mode:
BOOL hasGallery = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = hasGalleryt ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypePhotoLibrary;
if (self.popoverController != nil)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
CGRect popoverRect = [self.view convertRect:[self.imageView frame]
fromView:[self.imageView superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 300) ;
popoverRect.origin.x = popoverRect.origin.x;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Camera mode:
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary;
if (self.popoverController != nil)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
CGRect popoverRect = [self.view convertRect:[self.imageView frame]
fromView:[self.imageView superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 300) ;
popoverRect.origin.x = popoverRect.origin.x;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Remember to give to the .h File #interface the delegates, like this:
#interface the UIViewController: UIViewController <UIPopoverControllerDelegate, UIImagePickerControllerDelegate>

TabBar does not work after hidden = NO

I am faced a problem: after command self.tabBarController.tabBar.hidden = YES, I do something and then call: self.tabBarController.tabBar.hidden = NO, tabs do not work at all. It looks like frozen
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
self.tabBarController.tabBar.hidden = TRUE;
imagePickerController.showsCameraControls = YES;
}
self.imagePickerController = imagePickerController;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
self.tabBarController.tabBar.hidden = FALSE;
}
after pressing Cancel tab bar is appearing but tabs do not work at all

UIPickerController crashes the app

I have a UIPickerController that gets your pictures and allows you to pick some of them though at the moment when I click the button to activate it the app crashes.
Here is the code that I am using for it:
in my ViewDidLoad method:
pickerController = [[UIImagePickerController alloc] init];
pickerController.allowsEditing = NO;
pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
The function:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:nil];
patientPicture = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
UIImageView *pictureView = (UIImageView *)[imageCell viewWithTag:777];
pictureView.image = patientPicture;
[_imgViewAdd reloadInputViews];
}
And it being called:
- (IBAction)addPicture:(id)sender {
[self presentViewController:pickerController animated:YES completion:nil];
}
It is wierd because I have recently changed my app to Ipad only though while it was in IPhone it worked fine. When you click the button in NSLog this error message crops up which I supose is something to do with it:
UIStatusBarStyleBlackTranslucent is not available on this device.
I suspect this is quite a common issue that people have
Thanks in advance
Try presenting in a popover...
pickerController = [[UIImagePickerController alloc] init];
UIPopoverController *popOverController = [[UIPopoverController alloc] initWithContentViewController:pickerController];
popOverController.delegate = self;
and to present...
[popOverController presentPopoverFromRect:yourframe inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Resources