|
|
@@ -15,6 +15,7 @@
|
|
|
@property (nonatomic,strong) IBOutlet UIView *previewContainer;
|
|
|
@property (strong, nonatomic) IBOutlet UIView *maskView;
|
|
|
@property (strong, nonatomic) IBOutlet UIButton *scanBtn;
|
|
|
+@property (strong, nonatomic) IBOutlet UIButton *backBtn;
|
|
|
|
|
|
@property (nonatomic,strong) AVCaptureDevice *device;
|
|
|
@property (nonatomic,strong) AVCaptureDeviceInput *input;
|
|
|
@@ -29,6 +30,8 @@
|
|
|
@property (nonatomic,strong) CAShapeLayer *maskLayer;
|
|
|
@property (nonatomic,strong) CAShapeLayer *rectLayer;
|
|
|
|
|
|
+@property (nonatomic,assign) BOOL navigationBarStatus;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation RAQRCodeScannerViewController
|
|
|
@@ -45,6 +48,10 @@
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
+ if (self.navigationController) {
|
|
|
+ self.navigationBarStatus = self.navigationController.navigationBarHidden;
|
|
|
+ [self.navigationController setNavigationBarHidden:YES animated:NO];
|
|
|
+ }
|
|
|
|
|
|
self.scanerView.layer.borderColor = [UIColor blackColor].CGColor;
|
|
|
self.scanerView.layer.borderWidth = 0.5f;
|
|
|
@@ -77,10 +84,13 @@
|
|
|
|
|
|
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
|
|
|
NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
|
|
|
+ if (!appName) {
|
|
|
+ appName = [infoDict objectForKey:@"CFBundleName"];
|
|
|
+ }
|
|
|
__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];
|
|
|
+ [weakSelf didCancel];
|
|
|
}];
|
|
|
[alert addAction:action];
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
@@ -236,6 +246,17 @@
|
|
|
return _scanLineLayer;
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Private
|
|
|
+
|
|
|
+- (void)didCancel {
|
|
|
+ if (self.QRCodeViewControllerDidCanceled) {
|
|
|
+ self.QRCodeViewControllerDidCanceled(self);
|
|
|
+ if (self.navigationController) {
|
|
|
+ [self.navigationController setNavigationBarHidden:self.navigationBarStatus animated:NO];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Init
|
|
|
|
|
|
- (void)initCapture {
|
|
|
@@ -246,10 +267,13 @@
|
|
|
|
|
|
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
|
|
|
NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
|
|
|
+ if (!appName) {
|
|
|
+ appName = [infoDict objectForKey:@"CFBundleName"];
|
|
|
+ }
|
|
|
__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];
|
|
|
+ [weakSelf didCancel];
|
|
|
}];
|
|
|
[alert addAction:action];
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
@@ -326,10 +350,12 @@
|
|
|
|
|
|
AVMetadataMachineReadableCodeObject *metadataObject = [metadataObjects objectAtIndex:0];
|
|
|
NSString *codeValue = metadataObject.stringValue;
|
|
|
- if (self.completion) {
|
|
|
- self.completion(codeValue);
|
|
|
+ if (self.QRCodeViewControllerDidCompletion) {
|
|
|
+ self.QRCodeViewControllerDidCompletion(self, codeValue);
|
|
|
+ if (self.navigationController) {
|
|
|
+ [self.navigationController setNavigationBarHidden:self.navigationBarStatus animated:NO];
|
|
|
+ }
|
|
|
}
|
|
|
- [self.navigationController popViewControllerAnimated:YES];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -352,6 +378,10 @@
|
|
|
self.scannerEnable = NO;
|
|
|
}
|
|
|
|
|
|
+- (IBAction)backBtnClick:(UIButton *)sender {
|
|
|
+ [self didCancel];
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Utils
|
|
|
|
|
|
+ (UIImage *)imageWithColor:(UIColor *)color Size:(CGSize)size {
|