RichScanDemo

相机权限

奔溃问题:

1
[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

info.plist 添加权限字段: NSCameraUsageDescription

layer 导致问题

错误提示:

1
void UIViewReportBrokenSuperviewChain(UIView *__strong, UIView *__strong, BOOL)()

原因分析:

  1. 添加摄像头预览视图的layer

    1
    2
    3
    4
    5
    
       @property (strong,nonatomic)AVCaptureVideoPreviewLayer * preview;
       //覆盖视图
       @property (nonatomic, strong) UIView *overlayView;
    
       [self.view.layer insertSublayer:_preview atIndex:0];
  2. 添加遮罩层

    1
    2
    
       //问题行:    [self.view addSubview:self.overlayView];
       [self.view.layer insertSublayer:self.overlayView.layer atIndex:2];

结论:在VC初始化过程,self.view添加视图时,被添加的对象只能是一种,要么通过图层,要么添加UIView视图。同时添加会造成上述错误。参考: DEBUG - UIView.h#190 | 继刚的博客 Assertion failure in void UIViewReportBrokenSuperviewChain(UIView *__strong, …

UIButton layer层无法点击问题

解决办法,借助导航条实现:

  1. 目前只需要一个返回按钮,使用在导航条上添加返回按钮,避开在self.view添加button layer。

  2. 设置导航条透明IOS开发-UINavigationBar透明设置 - 简书

1
2
3
4
5
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}