首页 文章

xcode相机检查模拟器

提问于
浏览
3

我已经在我的应用程序中运行了相机,并且在模拟器中禁用了访问它的按钮,但是如果用户从不使用它,我也会弹出警报 . 如果他们的设备没有相机,我不希望它出现,我用过:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    //alert
}

但在模拟器中,它仍在运行警报 . 不幸的是,我没有没有相机的设备来测试它,我不确定是否存在问题 . 我不希望它运行,因为模拟器没有相机,对吧?

1 回答

  • 0

    这就是我为此目的所使用的:

    - (void) initializeCamera {
        AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        NSError *error = nil;
        AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
    
        if(!input) {
            // running on simulator or something else without camera
            NSLog(@"camera is not found");
        }
        else {
            // camera exists, you can alert
        }
    }
    

相关问题