问题
I init the UIImagePickerController:
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
and then use this method [imagePicker takePicture];
and I not get any call to the delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
Any idea why?
回答1:
You don't mention if you're actually presenting the image picker controller to the user by calling -presentViewController:animated:completion:
(or the older presentViewController:animated:
).
Apple's docs don't explicitly say so, but I'm pretty sure the image picker controller needs to be shown on screen in order for -takePicture
to work, otherwise you would be able to take pictures without the user knowing.
回答2:
To use an image picker controller, you must provide a delegate that conforms to the UIImagePickerControllerDelegate protocol.
if it does, verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the “UIImagePickerControllerSourceType” enum.
Also check 'self' hasn't been released.
来源:https://stackoverflow.com/questions/8068436/uiimagepickercontroller-takepicture-not-responding