Edit - I solved this myself - see the notes at the bottom
When using iOS7 on Xcode 5, I am using an option to take an image from a camera, or from the photo library, once the image is chosen (or a new picture taken) the view should flip over to the next screen.
This does not happen on the iPhone running iOS7, it works fine on the iPad, but the method is slightly different, but it does appear to be iPhone only problem on iOS7.
here is the code used, for example, on the choose image from library function;
-(void) choosePic {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeSavedPhotosAlbum];
cameraUI.allowsEditing = NO;
cameraUI.delegate = self;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
_popover = [[UIPopoverController alloc] initWithContentViewController:cameraUI];
[_popover presentPopoverFromRect:btnLibrary.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
[self presentModalViewController: cameraUI animated: YES];
}
}
Also, the code once picker is finished;
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
//Disable buttons
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self disableButtons];
//Get image
self.originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage];
//Dismiss
if(_popover)
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[_popover dismissPopoverAnimated:YES];
_popover = nil;
}
}
else
[picker dismissModalViewControllerAnimated: YES];
//Next
[self performSelector: #selector(nextScreen) withObject:nil afterDelay:0.5];
}
I fixed this by switching out;
[picker dismissModalViewControllerAnimated: YES];
With
[picker dismissViewControllerAnimated:NO completion:nil];
First you need to make sure that logic reaches the correct place it's intended to, try setting a breakpoint or NSLog before the iPhone's specific line, try this (You also missed curled braces, added them here) :
-(void) choosePic {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeSavedPhotosAlbum];
cameraUI.allowsEditing = NO;
cameraUI.delegate = self;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
_popover = [[UIPopoverController alloc] initWithContentViewController:cameraUI];
[_popover presentPopoverFromRect:btnLibrary.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else{
NSLog(#"Checkpoint !");
[self presentModalViewController: cameraUI animated: YES];
}
} }
Related
I am developing an app in which i need to keep open full screen camera open and also add a button on it(bottom right). I googled but couldn't find any healthy solution. Thanks in advance. Have a good day.
Edited
- (void) showCameraUI {
[self startCameraControllerFromViewController: self
usingDelegate: self];
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
NSLog(#"Start Camera Controller method...");
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// 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 presentModalViewController: cameraUI animated: YES];
return YES;
}
P.S: I also added UINavigationControllerDelegate,UIImagePickerControllerDelegate as protocol in header file, but its not still opening camera and show me default view of project.
you can simply capture image Using camera like bellow, i am using this bellow method in my code:-
-(void)btnCemeraOpen
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
yourImageView.image = [info valueForKey:#"UIImagePickerControllerOriginalImage"];
if(yourImageView==nil)
{
}
else
{
//DO logic
}
return;
}
i am creating an application which capture an image form iphone camera and display it in the created application i read some articles in ios developer library and written this code in .m file
- (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 picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// 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 presentModalViewController: cameraUI animated: YES];
return YES;
}
also created a button that is linked with this code,
It call this function but the control does not passes to the above function
- (IBAction) showCameraUI {
[self startCameraControllerFromViewController: self
usingDelegate: self];
}
And i also have no idea that this code will work or not
Do some one have any better idea.
Thanks,
Arun.
First assign delegate to it's source file
Then when you pressed your button implement this method open camera controller in your app
First of all create PopOverController for iPad because we cannot directly open ImagePicker Controller
EDIT: Added UIPopOverController
- (IBAction) showCameraUI {
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:[yourBtn frame]
fromView:[yourBtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
And implement this delegate method for get the captured image
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *yourImageView = image;
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
}
Implement this method if user cancel the controller
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
[picker dismissModalViewControllerAnimated:YES];
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
}
- (void)pickerDone:(id)sender
{
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
}
You can use delegate: UIImagePickerControllerDelegate
Use bellow:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)mediaAndInfo
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
I need help getting this code to work on iPad, it works fine on iPhone but for what ever reason not iPad.I have no idea what to do get this image picker to work on iPad. Any help will be appreciated.
-(IBAction)getCameraPicture:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController: picker animated:YES];
[picker release];
}
-(IBAction)selectExitingPicture
{
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
On iPad you need to show it inside a UIPopoverController, not present it modally.
You can display the UIImagePicker as a modalView in iPhone. But in iPad you need to use UIPopover as a container for displaying the imagePicker.
Re-write your code like:
-(IBAction)selectExitingPicture
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
self.popover = [[UIPopoverController alloc]
initWithContentViewController:picker];
popover.delegate = self;
[self.popover presentPopoverFromRect:CGRectMake(0,0,170,250)
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
else
{
[self presentModalViewController:picker animated:YES];
}
[picker release];
}
In your #interface add the necessary protocols and necessary instances
#interface yourController: UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate, UIPopoverControllerDelegate>
{
UIPopoverController *popover;
}
#property (nonatomic, strong) UIPopoverController *popover;
#end
It'll work on both iPad and iPhone.
You can try this:
Change the CGRectMake for custom popover and CGSizeMake for content size.
- (IBAction)imageFromAlbum:(id)sender
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// es iPad
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
//Averiguar si está en portrait o landscape
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
//PORTRAIT
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self cerrarTeclado];
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:CGRectMake(600, 400, 311, 350) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
[self.popover setPopoverContentSize:CGSizeMake(330, 515)];
}
//LANDSCAPE
if (orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft)
{
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:CGRectMake(850, 400, 311, 350) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
[self.popover setPopoverContentSize:CGSizeMake(330, 515)];
}
} else {
// no es iPad
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
I'm trying to present an UIImagePickerController. It works fine on simulator, but after few times of presenting, I get an error in the console.
More than maximum 5 filtered album lists trying to register.
This will fail.
Here is the code:
- (IBAction)imageSelectorPressed:(id)sender
{
UIImagePickerController* picker = [[[UIImagePickerController alloc] init] autorelease];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
// Set source to the Photo Library
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
}
picker.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.imagePopOverController = popover;
[self.imagePopOverController setDelegate:self];
[self.imagePopOverController presentPopoverFromRect:[kepekBtn frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popover release];
}
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
[popoverController dismissPopoverAnimated:YES];
[self setImagePopOverController:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.imagePopOverController dismissPopoverAnimated:NO];
[image setImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
picker = nil;
[self setImagePopOverController:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.imagePopOverController dismissPopoverAnimated:NO];
picker = nil;
[self setImagePopOverController:nil];
}
UPDATE: I've checked the contact app on the iPad. Edited a person, and it has a same error in the console log. BUT it is not crashing, while my app is. So the proper question: How can I fix it?
I'm trying to write code to select an image from the photo library on an iPad. The code that I'm using is below (taken from Apple's website), but it keeps giving me an error saying that On iPad, UIImagePickerController must be presented via UIPopoverController. I've tried changing this line: UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init]; to use a UIPopoverController, but obviously I'm doing something wrong because its not working.
- (BOOL) selectImage: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Displays saved pictures and movies, if both are available, from the
// Camera Roll album.
mediaUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeSavedPhotosAlbum];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
mediaUI.allowsEditing = NO;
mediaUI.delegate = delegate;
[controller presentModalViewController: mediaUI animated: YES];
return YES; }
The Apple Developer page also says: "On iPad, you can alternatively present the browser interface using a popover as described in initWithContentViewController: and “Presenting and Dismissing the Popover” in UIPopoverController Class Reference." I've read it but I still can't get it to work. Any help would be appreciated.
Something like this should work:
// create an image picker controller
UIImagePickerController *imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePickerController.delegate = self;
// present it in a popover
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:imagePickerController] autorelease];
self.popoverController.delegate = self;
// I was presenting the popover from a button, but you would set the rect to whatever is appropriate for your app
[self.popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Declare an ivar such as:
UIPopoverController *imagePopover;
Then:
imagePopover = [[UIPopoverController alloc] initWithContentViewController:mediaUI];
[imagePopover setDelegate:self];
[imagePopover presentPopoverFromRect:someRect
inView:someView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
in place of
[controller presentModal...];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
refer below link
http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_%28Xcode_4%29
I went through a lot of pain coming up with a solution which works on both iPad and iPhone, this is the final code which some of it comes from comments of other people:
the code has some bugs but it's a very good place to start :)
it covers permissions needed as well as how to manage viewcontrollers popoing up on ipad.
requires following imports :
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
and add this delegates :
UIActionSheetDelegate, UIImagePickerControllerDelegate
definitions :
__weak IBOutlet UIButton *attachButton;
UIImage *image;
button's action :
- (IBAction)doAttach:(id)sender {
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:#"Select image from" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"From library",#"From camera", nil] ;
[action showInView:self.view];
}
#pragma mark - ActionSheet delegates
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if( buttonIndex == 1 ) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
NSLog(#"%#", #"You have camera access");
}
else if(authStatus == AVAuthorizationStatusDenied)
{
NSLog(#"%#", #"Denied camera access");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(#"Granted access to %#", AVMediaTypeVideo);
} else {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“no camera access“
message: #“if you need to use camera in this application go to settings -> appName -> and turn on camera.”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
NSLog(#"Not granted access to %#", AVMediaTypeVideo);
return ;
}
}];
}
else if(authStatus == AVAuthorizationStatusRestricted)
{
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“no camera access“
message: #“if you need to use camera in this application go to settings -> appName -> and turn on camera.”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
NSLog(#"%#", #"Restricted, normally won't happen");
}
else if(authStatus == AVAuthorizationStatusNotDetermined)
{
NSLog(#"%#", #"Camera access not determined. Ask for permission.");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(#"Granted access to %#", AVMediaTypeVideo);
} else {
NSLog(#"Not granted access to %#", AVMediaTypeVideo);
return ;
}
}];
}
else
{
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“No camera access“
message: #“error accusing camera”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
return;
//NSLog(#"%#", #"Camera access unknown error.");
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *pickerView =[[UIImagePickerController alloc]init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
pickerView.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[ self.presentedViewController dismissViewControllerAnimated:YES completion:nil ];
pickerView.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = pickerView.popoverPresentationController;
popPC.sourceView = attachButton;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:pickerView animated:YES completion:nil];
} else {
[self presentModalViewController:pickerView animated:YES ];
}
}
}else if( buttonIndex == 0 ) {
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
switch (status) {
case ALAuthorizationStatusRestricted:
case ALAuthorizationStatusDenied:
{
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“no access to library”
message: #“if you wish to access photos in this app go to settings -> appName-> and turn on photos .”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
break;
default:
{
UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[ self.presentedViewController dismissViewControllerAnimated:YES completion:nil ];
pickerView.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popup = pickerView.popoverPresentationController;
popup.sourceView = attachButton;
popup.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:pickerView animated:YES completion:nil];
} else {
[self presentModalViewController:pickerView animated:YES ];
}
}
break;
}
}
}
#pragma mark - PickerDelegates
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[self dismissModalViewControllerAnimated:true];
UIImage * img = [info valueForKey:UIImagePickerControllerEditedImage];
image = img;
}