|
|
@@ -55,7 +55,42 @@
|
|
|
[self.scanBtn setImage:normal_img forState:UIControlStateNormal];
|
|
|
[self.scanBtn setImage:highlight_img forState:UIControlStateHighlighted];
|
|
|
|
|
|
- [self initCapture];
|
|
|
+ if ([self camerAuthorization]) {
|
|
|
+
|
|
|
+ [self initCapture];
|
|
|
+
|
|
|
+ } else {
|
|
|
+ [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+
|
|
|
+ if (granted) {
|
|
|
+
|
|
|
+ [self initCapture];
|
|
|
+ [self resetPreview];
|
|
|
+
|
|
|
+ if (![self.session isRunning]) {
|
|
|
+ [self.session startRunning];
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
|
|
|
+ NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [weakSelf dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ }];
|
|
|
+ [alert addAction:action];
|
|
|
+ [self presentViewController:alert animated:YES completion:nil];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
|
|
|
@@ -93,6 +128,38 @@
|
|
|
- (void)viewDidLayoutSubviews {
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
|
+ [self resetPreview];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
|
+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
|
|
+
|
|
|
+// NSLog(@"device orientation: %ld & statusbar orientaion: %ld",[UIDevice currentDevice].orientation,[UIApplication sharedApplication].statusBarOrientation);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+
|
|
|
+ if (self.scannerInitial) {
|
|
|
+ [self.session startRunning];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillDisappear:(BOOL)animated {
|
|
|
+ [super viewWillDisappear:animated];
|
|
|
+
|
|
|
+ if ([self.session isRunning]) {
|
|
|
+ [self.session stopRunning];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)didReceiveMemoryWarning {
|
|
|
+ [super didReceiveMemoryWarning];
|
|
|
+ // Dispose of any resources that can be recreated.
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetPreview {
|
|
|
+
|
|
|
self.previewLayer.frame = self.previewContainer.bounds;
|
|
|
AVCaptureVideoOrientation orientation = [self captureVideoOrientation];
|
|
|
if (self.previewLayer.connection.isVideoOrientationSupported) {
|
|
|
@@ -133,14 +200,14 @@
|
|
|
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.maskView.bounds];
|
|
|
UIBezierPath *subPath = [UIBezierPath bezierPathWithRect:self.scanerView.frame];
|
|
|
[path appendPath:subPath];
|
|
|
-
|
|
|
+
|
|
|
if (!self.maskLayer) {
|
|
|
self.maskLayer = [CAShapeLayer layer];
|
|
|
self.maskLayer.fillColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.5].CGColor;
|
|
|
self.maskLayer.fillRule = kCAFillRuleEvenOdd;
|
|
|
}
|
|
|
self.maskLayer.path = path.CGPath;
|
|
|
-
|
|
|
+
|
|
|
if (!self.rectLayer) {
|
|
|
self.rectLayer = [CAShapeLayer layer];
|
|
|
self.rectLayer.fillColor = [UIColor clearColor].CGColor;
|
|
|
@@ -153,33 +220,6 @@
|
|
|
[self.maskView.layer addSublayer:self.maskLayer];
|
|
|
}
|
|
|
|
|
|
-- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
|
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
|
|
-
|
|
|
-// NSLog(@"device orientation: %ld & statusbar orientaion: %ld",[UIDevice currentDevice].orientation,[UIApplication sharedApplication].statusBarOrientation);
|
|
|
-}
|
|
|
-
|
|
|
-- (void)viewWillAppear:(BOOL)animated {
|
|
|
- [super viewWillAppear:animated];
|
|
|
-
|
|
|
- if (self.scannerInitial) {
|
|
|
- [self.session startRunning];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)viewWillDisappear:(BOOL)animated {
|
|
|
- [super viewWillDisappear:animated];
|
|
|
-
|
|
|
- if ([self.session isRunning]) {
|
|
|
- [self.session stopRunning];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)didReceiveMemoryWarning {
|
|
|
- [super didReceiveMemoryWarning];
|
|
|
- // Dispose of any resources that can be recreated.
|
|
|
-}
|
|
|
-
|
|
|
- (CAGradientLayer *)scanLineLayer {
|
|
|
if (!_scanLineLayer) {
|
|
|
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
|
|
|
@@ -205,7 +245,7 @@
|
|
|
if (![self camerAuthorization]) {
|
|
|
|
|
|
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
|
|
|
- NSString *appName = [infoDict objectForKey:@"CFBundleName"];
|
|
|
+ NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
|
|
|
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|