Presented UIImagePickerController camera could take photo or cancel - xcode

I have UIImagePickerController which opens a camera, as the sample code bellow shows.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
imagePicker.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:imagePicker
animated:YES
completion:NULL];
My Problem: When I present the camera, the camera shows, but I could not take a picture nor tap to cancel. Even the flip camera icon does not respond.
Happening on iOS versions below 8, iPad.

i tried your code and its working on iPad 2 iOs7.1.2
you might try using setters, this is how i am doing it
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setAllowsEditing:YES];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[picker setModalPresentationStyle:UIModalPresentationPageSheet];
}
else
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[picker setDelegate:self];
[self presentViewController:picker animated:YES completion:nil];

Related

UISplitViewControllerDisplayModePrimaryOverlay causes "Unbalanced calls to begin/end appearance transitions"

In iOS 8, setting the preferredDisplayMode on a UISplitViewController to PrimaryOverlay is generating the following warning:
"Unbalanced calls to begin/end appearance transitions for UINavigationController"
There is no problem if I set preferredDisplayMode to AllVisible or don't set it at all. Problem occurs for all iPads and iPhones in the simulator that I've tried. Problem occurs whether the app starts up in portrait or landscape.
Here's some very simple code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITableViewController *tableViewController = [[UITableViewController alloc] init];
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *masterNavController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
UINavigationController *detailNavController = [[UINavigationController alloc] initWithRootViewController:viewController];
UISplitViewController *svc = [[UISplitViewController alloc] init];
[svc addChildViewController:masterNavController];
[svc addChildViewController:detailNavController];
//svc.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
svc.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
self.window.rootViewController = svc;
[self.window makeKeyAndVisible];
return YES;
}
Wrap your display code in dispatch_async. Otherwise iOS seems to get confused with other animations running at the same time.
dispatch_async(dispatch_get_main_queue(), ^{
svc.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
});
or
dispatch_async(dispatch_get_main_queue()) {
svc.preferredDisplayMode = .PrimaryOverlay
}

ALAssetsLibrary writeImageToSavedPhotosAlbum block the program in iOS8

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSMutableDictionary* meta = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
if(self.locationManager.location){
NSDictionary* locationMeta = [self gpsDictionaryForLocation:self.locationManager.location];
[meta setObject:locationMeta forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:img.CGImage metadata:meta completionBlock:^(NSURL* assetUrl, NSError* error){
//.......
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
This code worked fine in iOS7. After I upgraded my device to iOS8, the program was blocked and imagePickerView didn't dismiss.
Is this a bug in iOS8? Anyone can help me?

Take Photos from camera and library

hi in my app i am able to take a photo or select a photo from library and display it in a imageview
but my question is how can i add a second image view and display a image in that
here is my code
- (IBAction)TakePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)ChoosePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[ImageView setImage:image]; // "myImageView" name of any UImageView.
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
What I think from your question is you are going to select two image one bye one.
Either from camera or from photo library.
Try this one:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
if(ImageView.image == Nil)
{
[ImageView setImage:image];
}
else if(ImageView2.image == Nil)
{
[ImageView2 setImage:image];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}

iOS6 problems to Tweet in UITabBarController using image taken from UIImagePickerController

After picking image from UIImagePickerController I want to Tweet it but there is error!
Warning: Attempt to present <SLTwitterComposeViewController: 0x210d84b0> on <UITabBarController: 0x1fd67650> while a presentation is in progress!
P.S
This is tabbar application (4 tabbars)
All code:
-(void)useCamera:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
_newMedia = YES;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
[self buttonTweet:info[UIImagePickerControllerOriginalImage]];
}
}
- (IBAction)buttonTweet:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:[NSString stringWithFormat:#"#this is tweet text"]];
[composeController addImage:sender];
[composeController addURL: [NSURL URLWithString:#"http://www.abc.com"]];
[self presentViewController:composeController animated:YES completion:nil];
}
You are presenting a new view controller while the old one is still disappearing. You can present the new one upon completion of the other animation by doing it like this:
[self dismissViewControllerAnimated:YES completion:^{
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
[self buttonTweet:info[UIImagePickerControllerOriginalImage]];
}
}];

UIImage Picker autorotation feature disappeared suddenly

I was using UIImagePickerController without any problem.
Before when I was taking a picture in the landscape mode, the picture in the Preview (when the buttons Retake and Use Photo were present) was always automatically rotated so as to appear correctly in the portrait mode.
But now when I use the UIImagePickerController the preview mode does not rotate the picture anymore.
Where can I activate or desactivate this mode?
Here is my code:
- (IBAction)getCameraPicture{
//Create an UIImagePickerController to be able to take a picture
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsImageEditing = NO;
[self presentModalViewController:picker animated:YES];
[picker release];
- (IBAction)selectExistingPicture{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//Here is specified the fact that the picker source is the library
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error accessing photo library" message:#"Device does not support a photo library" delegate:nil cancelButtonTitle:#"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
int imageCase=0;
UIImage *imageSaved=rotateImage(image);
UIImage* imageNormal =scaleImage(imageSaved,imageCase);
imageView.image = imageNormal;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
I really need to at least understand what is happening so any help would be really appreciated even if it is not the solution!
Thanks folks!
one possibility is that you need to call
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Resources