相机未在iPad物镜c中打开

时间:2018-02-05 14:23:08

标签: ios objective-c ipad camera uiimagepickercontroller

我可以使用相机和照片库在iPhone上选择照片。但是,同样的事情不适用于iPad。阅读几个教程,但我不确定出了什么问题。

@property (nonatomic, strong) UIPopoverController *popOver;

-(void)captureImage:(NSInteger)sourceType{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        [self cameraUsingiPad];
        return;
    }
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = sourceType;
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:nil];

}else{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Camera Unavailable" message:@"Unable to find a camera on your device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    alert = nil;
}

}

-(void) cameraUsingiPad {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = NO;
self.popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
[self.popOver presentPopoverFromRect:self.view.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

2 个答案:

答案 0 :(得分:0)

在iOS 10和11中,用户必须允许使用相机。 因此,您应该在info.plist中添加说明。

enter image description here

答案 1 :(得分:0)

问题在于权限。修好了。