如何在iOS10中启用相机的拍照选项

时间:2016-10-18 11:10:22

标签: ios camera uiimagepickercontroller

在iOS10中点击相机选择拍照不用手动点击那个自动拍照,那么如何通过手动点击创建拍照? 我尝试了以下代码:

- (void)cameraAndPhotogalleryMethod{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    picker.showsCameraControls = YES;
    [self presentViewController:picker animated:YES
                     completion:^ {
                         [picker takePicture];
                     }];
}
else
{
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}}

- (void)cameraMethod{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.showsCameraControls = YES;
[self presentViewController:picker animated:YES
                 completion:^ {
                     [picker takePicture];
                 }];}

2 个答案:

答案 0 :(得分:1)

在info.plist文件中添加此属性

image

答案 1 :(得分:0)

1.如果你在ios上访问相机10.你应该在plist中添加代码。试试这段代码。

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to use your camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to use your photo  library</string>