iPad UIImagePicker in UIPopoverController selecting only Saved images (not from Album)? - ipad

In my iPad application, I'm letting the user select an image using the following code:
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController presentPopoverFromRect:self.view.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[picker release];
(I've set up the class to be both a UIPopoverControllerDelegate and a UIImagePickerControllerDelegate, and I've setup the callbacks for both delegates.)
Now, the weird thing is that if I select an image from the "Saved Photos" photo album, my "imagePickerController: didFinishPickingImage" callback method gets called, and I get an image, and all is well.
But, if I select an image from any of the other albums, my "imagePickerControllerDidCancel" callback gets called - and I don't get back an image.
Any idea? I've searched the web high-and-low...
Thanks,
Reuven
The plot thickens...
When adding:
allowsEditing = YES;
I can still select (and crop/scale) images from the Saved Photos album - but when trying to Use images from other albums, the iPad crashes with the debugger showing:
2010-06-03 08:16:06.759 uPrintMobile[98412:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: UIImagePickerControllerOriginalImage)'
Still no clue...

I know this is many months later, but I struggled with the same problem and found that though it was asked here many times, it was never answered. Well, I'm happy to say that I figured it out and so am posting it on a few of the nearly-identical questions that come up first on a search.
I posted the full answer here:
didFinishPickingMediaWithInfo return nil photo

Try playing around the other options of UIImagePickerControllerSourceTypePhotoLibrary
in your delegate method, check the condition like
`if( image is from photo library ) {
// do something
} else if ( image from saved albums ) {
// do something
}`

Related

i want to display google place picker for restaurants using GMSPlacePickerViewController, below are the code i am trying from developers.google.com

i want to achieve above screenshot output in one of my app below is the sample code i am looking at in developers website.
https://developers.google.com/places/ios-api/placepicker
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:nil];
GMSPlacePickerViewController *placePicker = [[GMSPlacePickerViewController alloc] initWithConfig:config];
placePicker.delegate = self;
[self presentViewController:placePicker animated:YES completion:nil];
GMSPlacePickerViewController is not visible to class it seems.
below attached is the error i am getting while putting this code to my class.
Let me know if anyone of you have worked on this.
Thanks in advance.

How to detect whether user select picture or video from library while using UIImagePickerController in iOS?

I'm using UIImagePickerController in my ios application to give an option to user to select photo or video from photo library. I'm restricting the video to 1 minute.
Here is my code:
In a button action:
- (void)getPictureOrVideoFromLibrary {
CFStringRef mTypes[2] = { kUTTypeImage, kUTTypeMovie };
CFArrayRef mTypesArray = CFArrayCreate(CFAllocatorGetDefault(), (const void**)mTypes, 2, &kCFTypeArrayCallBacks);
imagePickerController.mediaTypes = (__bridge NSArray*)mTypesArray;
CFRelease(mTypesArray);
imagePickerController.videoMaximumDuration = 60.0f;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
I want show both pictures and videos in photolibrary, so i have used both kUTTypeImage and kUTTypeMovie.
Here i'm setting videoMaximumDuration to 60.0f and allowsEditing to YES because i want to restrict the video length to 1 minute.
The problem i'm facing:
when user selects video from library there is no issue, but if user selects picture from library i'm getting problem, a rectangle box on picture.
The Picker shows like this(With videos and pictures)[screenshot1]:
when user selects video it is showing like this(It's working as expected):
When user selects picture it is showing like this [screenshot2]:
I don't want to show rectangle crop box here.
After user press 'Choose', i will be able to detect whether it is photo or video in delegate method 'didFinishPickingMediaWithInfo'.
But i want to know whether it is photo or video from screenshot1 to screenshot2. so that i can set allowsediting to NO to get rid of that rectangle box.
Is it possible?
I don't want to show both options as 'Select photo from library', 'Select video from library'.
I just want to show only one option as 'Select Photo or Video from library'.
Is there any way to detect whether user selects picture or video, or is it possible to get rid of that rectangle box?
Is it possible to achieve?
I need your valuable suggestions.
Please help me.
Thanks in advance.
check like this on delegate method
- (void)imagePickerController:(UIImagePickerController *)pickerImage didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// UIImagePickerControllerMediaType
if(info[UIImagePickerControllerMediaType]==kUTTypeImage)
{
//image
}
else
{
//video
}
}
1) add MobileCoreServices.framework
2) import below header file. MobileCoreServices/MobileCoreServices.h
Just Little bit change in #shesh nath's answer. I just convert kUTTypeImage to NSString to solve this warning :
Comparison of distinct pointer types ('id _Nullable' and 'CFStringRef'
(aka 'const struct __CFString *'))
- (void)imagePickerController:(UIImagePickerController*)imagePicker didFinishPickingMediaWithInfo:(NSDictionary*)info {
if([info[UIImagePickerControllerMediaType] isEqualToString:(__bridge NSString *)(kUTTypeImage)])
{
NSLog(#"Image");
//image
}
else
{
NSLog(#"Video");
//video
}
}
And don't forget to add MobileCoreServices framework.

Camera has black screen in UIImagepickercontroller in iOS

I'm facing the black screen preview in UIIMagePickercontroller. I tried many solutions but cannot solved that. Any body can help me to solve that? It's always happens when I open the photo library and select some photos, then add new cellItem in UICollectionview, after that I open camera to take new photo and the issue is happened.
Here is my code used to open Camera:
-(void)actionLaunchAppCamera
{
dispatch_async(dispatch_get_main_queue(), ^{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (self.cameraPickerController == nil) {
self.cameraPickerController= [[UIImagePickerController alloc] init];
self.cameraPickerController.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraPickerController.showsCameraControls = YES;
self.cameraPickerController.allowsEditing = YES;
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// self.cameraPickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto||UIImagePickerControllerCameraCaptureModeVideo;
self.cameraPickerController.delegate = self;
self.cameraPickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.cameraPickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.cameraPickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.cameraPickerController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:self.cameraPickerController
animated:YES completion:^
{
// BE SURE TO USE a completion block!!!
// completion stuff in here
}];
}
}
});
}
Thanks in advance.
I tried everything without luck until I set my Bundle Display Name to "whatever", in the Info.plist.
After this, the app asked for permissions as expected and the camera works.
I only wasted a day on this, which seems well below the median on StackOverflow. Hope it rescues others from this torturous bug.
The problem is not your code. It's apple's API. You can make see the same problem in Apple contact, if you edit the picture, save it and then go back and edit it agin. Then you will have a black preview. Take a picture any way and repeat the process, then it will be fine. It also does it in text message picture. Reset the device to factory settings and everything will work for a while. I have reported to Apple 3 months ago and still nothing from them. One would think if Apple had a bug report in their core apps they would fix it. This problem has really been a pain and yet IOS 6 had no problems.

GKPeerPickerController is blank when invoked within EAGLView

I have an EAGLView-based class that runs the following code when a menu selection is made in OpenGL:
-(void) startPicker
{
self.gameState = kStatePicker;
GKPeerPickerController *picker = [[GKPeerPickerController alloc] init];
picker.delegate = self;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[picker show];
}
For some unknown reason, the picker is a blank rounded rect when it appears, with no visible interface or directions.
If I launch it at the end of my init function, it works. Afterward, it launches fine from the menu.
I have tried placing the code in startPicker inside a main queue dispatch, but that doesn't seem to help. I've tried running the picker with and without ARC, but that makes no difference. This code is more or less directly taken from the GKTank example that Apple provided a while ago, to introduce GameKit's bluetooth framework.
Can anyone tell me why this might be happening, and what a possible solution is?
Just following up. I discovered in the view controller that contains this view that there was a call to [UIView setAnimations:NO]; This prohibits GKPeerPickerController from appearing properly.

Choosing From Library using UIImagePickerControllerSourceTypeSavedPhotosAlbum

I would like to have choosing images or videos as one option when taking photos or videos. When i seem to click the option, the app crashes. I am using ios 6 and it seems that apple has included some privacy issues when the app tries to search for existing images and videos. Besides that, should i still be using UIImagePickerControllerSourceTypeSavedPhotosAlbum or use something else?
Part of my code:
if (buttonIndex == 2) {
imgpPicker = [[UIImagePickerController alloc] init];
imgpPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imgpPicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage,nil];
popOverView = [[UIPopoverController alloc] initWithContentViewController:imgpPicker];
[popOverView presentPopoverFromRect:self.view.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
The error that appears on the debugger is signal SIGABRT:
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
*** First throw call stack:
(0x36a732a3 0x33e9a97f 0x36a731c5 0x3777d897 0x3777d6a1 0x3777d65b 0x3777ce1b 0x3777cb45 0x37735767 0x377355c7 0x377355c7 0x3772fe53 0x377177e5 0x377172cb 0x37b00b95 0x115313 0x378d6ccb 0x378000ad 0x3780005f 0x3780003d 0x377ff8f3 0x377ffde9 0x377285f9 0x37715809 0x37715123 0x3644d5a3 0x3644d1d3 0x36a48173 0x36a48117 0x36a46f99 0x369b9ebd 0x369b9d49 0x3644c2eb 0x37769301 0xe1763 0xe14c0)
libc++abi.dylib: terminate called throwing an exception
(lldb)
The privacy for the application is also set to ON in the settings.
Am i doing something wrong?
Any guidance or tips will be very helpful. Sorry if the question is very vague.. If need more information, I can provide...
In your code add:
- (BOOL)shouldAutorotate
{
return YES;
}
And go to the summary tab of your application and allow both portrait and landscape orientations.

Resources