【问题标题】:accessing camera if user click on "dont allow" button when opening the camera如果用户在打开相机时单击“不允许”按钮,则访问相机
【发布时间】:2015-02-23 13:46:23
【问题描述】:

这是我第一次使用相机。让我解释一下我的应用程序。它由一个录制按钮组成,当用户单击录制按钮时,它会打开相机并要求用户授予访问权限相机和麦克风。因此,如果用户在询问相机或麦克风或访问照片时单击“不允许”按钮,尽管他单击“不允许”按钮,但我可以打开相机。以下是我用来打开相机的代码

 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);
   }
     }];

如果用户在提示使用相机或麦克风时点击“不允许”按钮,我是否有必要关闭相机。如果点击“不允许”,我可以打开相机。我不想访问任何画廊视频.用户只需录制视频并上传到服务器。

在此先感谢....

【问题讨论】:

    标签: ios objective-c iphone xcode camera


    【解决方案1】:

    转到设置并转到您的应用,然后单击隐私并打开相机开关。 (或者) 转到设置并转到隐私并打开您应用上的相机开关。

    【讨论】:

      猜你喜欢
      • 2016-04-20
      • 2018-03-21
      • 2022-01-01
      • 1970-01-01
      • 2012-12-08
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多