0
UIImagePickerControllerSourceType source = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
[self presentViewController:picker animated:YES completion:NULL];

working all good with UIImagePickerControllerSourceTypeSavedPhotosAlbum. all the permissions are given in plist for privacy. changed the app target as well seems like nothing is working for me. currently app target is ios 8.

Rishi
  • 1
  • 1
    iOS 8 have such issue already report, give this a try: http://stackoverflow.com/questions/26652338/camera-show-black-screen-in-ios-8. Although you said you have added keys to plist but it doesn't tell you are authorized to capture too. – NeverHopeless May 02 '17 at 13:18
  • i already added code to check authorization part. Even changed the target to 9/10. when the camera view get present and i click on capture button all went wrong with the only blck preview sayg "cncl" and "use photo". dat means b4 the control goes to delegate "didFinishPickingMediaWithInfo" i got the black preview .1 more thing i want to add here, i change the allowsEditing to NO, got the image preview and try to pick d "UIImagePickerControllerOriginalImage" app gets crash before the control comes to delegate - "setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)'" – Rishi May 03 '17 at 05:07
  • Which Xcode you are using ? Also can you please try suggestions provided here: http://stackoverflow.com/questions/19081701/ios-7-uiimagepickercontroller-has-black-preview specially related to GCD (use UIKit in main thread) and bundle name. – NeverHopeless May 03 '17 at 06:40
  • xcode - 8.2.1. Bundle name is given in plist. i got the permission pop up "App_name wants to access camera" . and my camera code is running on main thread. – Rishi May 03 '17 at 07:57
  • As you said in a comment "change the allowsEditing to NO, got the image preview" is that means you got the camera display instead of black screen? If yes, then what is the crash message you received on picking image ? – NeverHopeless May 03 '17 at 08:33
  • "setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)'" this is the reason for crash. but the strange thing is the app crashes before the didFinishPickingMediaWithInfo calls. – Rishi May 03 '17 at 09:19
  • 1 thing more the app is develop with target ios 7 with the older xcode version. now i faced this issue while working on 2nd version of app with latest xcode. – Rishi May 03 '17 at 09:20
  • Have you checked it with more than 1 device ? – NeverHopeless May 03 '17 at 09:45
  • yes ! iphone 5s, 6, 7 . issue is in all devices. – Rishi May 03 '17 at 10:07
  • As you said "1 thing more the app is develop with target ios 7 with the older xcode version. now i faced this issue while working on 2nd version of app with latest xcode.`. Can you implement this image capture code in a test project to see if the problem persists with the code or with the setup in this specific project which is now upgraded? – NeverHopeless May 03 '17 at 10:23
  • yes i did :) its working perfectly with the test code. any other suggestion will be appreciated! – Rishi May 03 '17 at 11:10

1 Answers1

0

its not Answer. A suggestion, Please check Device Space. /**************/ use this Code :

 UIImagePickerController *picker = [[UIImagePickerController alloc] init];
   picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  picker.delegate = self;
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:nil];

Don't set media type

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

 [picker dismissViewControllerAnimated:YES completion:nil];

}

/*********permission*****************/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<string>pro_name Camera Access</string>
</plist>
Ajjjjjjjj
  • 669
  • 4
  • 12
  • setting alloweditiing YES and picking UIImagePickerControllerOriginalImage will returns you nil image. Plus i aready tried with not setting media type but again my preview screen is black with saying "cancel" and "use photo". Any other suggestions with be appreciated. – Rishi May 03 '17 at 05:15