这是我第一次使用相机。让我解释一下我的App.It包含一个记录按钮,当用户点击记录按钮时,它会打开相机并要求用户授予访问权限。如果用户在被要求使用相机或麦克风或访问照片时点击“不允许”按钮,我可以打开相机,虽然他点击了“不允许”按钮。下面是我用来打开相机的代码
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// alert the user that the camera can't be accessed
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Unable to access the camera!" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[noCameraAlert show];
} else {
imagePickerCustom = [[UIImagePickerController alloc] init];
imagePickerCustom.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerCustom.delegate = self;
imagePickerCustom.allowsEditing = NO;
imagePickerCustom.showsCameraControls = NO;
imagePickerCustom.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imagePickerCustom.videoMaximumDuration = 61;
imagePickerCustom.videoQuality = UIImagePickerControllerQualityTypeMedium;
imagePickerCustom.navigationBarHidden = YES;
imagePickerCustom.toolbarHidden = YES;
imagePickerCustom.wantsFullScreenLayout = YES;
//add tap gesture on camera
// UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self
// action:@selector(handleSingleTap:)];
imagePickerCustom.wantsFullScreenLayout = YES;
//to get camera full screen
imagePickerCustom.cameraViewTransform = CGAffineTransformScale(imagePickerCustom.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM);
imagePickerCustom.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
imagePickerCustom.videoQuality = UIImagePickerControllerQualityTypeMedium;
NSArray *sourceTypes =
[UIImagePickerController availableMediaTypesForSourceType:imagePickerCustom.sourceType];
if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){
NSLog(@"Can't save videos");
}
else if{
NSLog(@"open camera overlayview");
}
我知道一些检测用户访问相机的代码
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
[lib enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"%i",[group numberOfAssets]);
} failureBlock:^(NSError *error) {
if (error.code == ALAssetsLibraryAccessUserDeniedError) {
NSLog(@"user denied access, code: %i",error.code);
}else{
NSLog(@"Other error code: %i",error.code);
}
}];
如果用户在提示使用相机或麦克风时点击“不允许”按钮,我是否有必要关闭相机。如果点击“不允许”我可以打开相机。我不想访问任何画廊视频。用户只记录视频并上传到服务器。
提前致谢....
答案 0 :(得分:0)
转到设置并转到您的应用并点击隐私并打开相机开关。 (要么) 转到设置并进入隐私状态并打开应用程序上的相机开关。