UIImagePickerController takePicture not responding

2019-08-05 18:47发布

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?

2条回答
smile是对你的礼貌
2楼-- · 2019-08-05 19:32

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.

查看更多
在下西门庆
3楼-- · 2019-08-05 19:52

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.

查看更多
登录 后发表回答