Bladeren bron

1.上架登录页

huangxiaodong 5 maanden geleden
bovenliggende
commit
583d1aadba

+ 12 - 0
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -136,6 +136,10 @@
 		18FCE5482AD15E750020F623 /* PlayerViewController+AppDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 18FCE5462AD15E730020F623 /* PlayerViewController+AppDelegate.h */; };
 		18FCE5492AD15E750020F623 /* PlayerViewController+AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 18FCE5472AD15E750020F623 /* PlayerViewController+AppDelegate.m */; };
 		5D9E1B185552EF17AE8B5F24 /* libPods-计算器.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CAE4E9905D1AB335F8657436 /* libPods-计算器.a */; };
+		6B00C7362D3A5E6E00EA2AE2 /* ScanToLoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B00C7352D3A5E6E00EA2AE2 /* ScanToLoginViewController.m */; };
+		6B00C7372D3A5E6E00EA2AE2 /* ScanToLoginViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B00C7342D3A5E6E00EA2AE2 /* ScanToLoginViewController.h */; };
+		6B00C7382D3A5E6E00EA2AE2 /* ScanToLoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B00C7352D3A5E6E00EA2AE2 /* ScanToLoginViewController.m */; };
+		6B00C7392D3A5E6E00EA2AE2 /* ScanToLoginViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B00C7342D3A5E6E00EA2AE2 /* ScanToLoginViewController.h */; };
 		6B05815B2AFC851E00D37290 /* mySetHeadView.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B0581592AFC851E00D37290 /* mySetHeadView.h */; };
 		6B05815C2AFC851E00D37290 /* mySetHeadView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B05815A2AFC851E00D37290 /* mySetHeadView.m */; };
 		6B0581602AFCD0DF00D37290 /* uploadImageOrVideoViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B05815E2AFCD0DF00D37290 /* uploadImageOrVideoViewController.h */; };
@@ -1667,6 +1671,8 @@
 		34FDFD4EDCAAF106290BB4FC /* Pods-隐私保护.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-隐私保护.debug.xcconfig"; path = "Target Support Files/Pods-隐私保护/Pods-隐私保护.debug.xcconfig"; sourceTree = "<group>"; };
 		41C5601DC8FC86BACEE00639 /* libPods-隐私保护.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-隐私保护.a"; sourceTree = BUILT_PRODUCTS_DIR; };
 		5A7C795CAC690A410AE1E306 /* libPods-隐私保护-双子星云手机UITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-隐私保护-双子星云手机UITests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
+		6B00C7342D3A5E6E00EA2AE2 /* ScanToLoginViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScanToLoginViewController.h; sourceTree = "<group>"; };
+		6B00C7352D3A5E6E00EA2AE2 /* ScanToLoginViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScanToLoginViewController.m; sourceTree = "<group>"; };
 		6B0581592AFC851E00D37290 /* mySetHeadView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mySetHeadView.h; sourceTree = "<group>"; };
 		6B05815A2AFC851E00D37290 /* mySetHeadView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = mySetHeadView.m; sourceTree = "<group>"; };
 		6B05815E2AFCD0DF00D37290 /* uploadImageOrVideoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = uploadImageOrVideoViewController.h; sourceTree = "<group>"; };
@@ -2514,6 +2520,8 @@
 				6BFF26982AFA16DA00FCB4F7 /* forgetSecretKeyViewController.m */,
 				6BBAE9412D38A20400C0F41B /* LoginType1ViewController.h */,
 				6BBAE9422D38A20400C0F41B /* LoginType1ViewController.m */,
+				6B00C7342D3A5E6E00EA2AE2 /* ScanToLoginViewController.h */,
+				6B00C7352D3A5E6E00EA2AE2 /* ScanToLoginViewController.m */,
 			);
 			path = Guide;
 			sourceTree = "<group>";
@@ -4376,6 +4384,7 @@
 				183AE7C72A8CB39100B11CB0 /* SafeForKey.h in Headers */,
 				6B7EA7AA2BF72D3B002D5CC2 /* queryShareModel.h in Headers */,
 				6B93549B2BF369D000AA8D31 /* previewToUploadFileView.h in Headers */,
+				6B00C7372D3A5E6E00EA2AE2 /* ScanToLoginViewController.h in Headers */,
 				6B5D40272B4BC402000965CF /* couldPhoneFileListModel.h in Headers */,
 				6B07E0AD2C3D1ED5004A3238 /* nasLastFileViewController.h in Headers */,
 				6B5B606E2B3D7E3B009A2AE2 /* fileTransferPathCheckViewController.h in Headers */,
@@ -4672,6 +4681,7 @@
 				6BD5070D2B9576A4006E7CB0 /* SafeForKey.h in Headers */,
 				6B7EA7AC2BF72D3B002D5CC2 /* queryShareModel.h in Headers */,
 				6B93549C2BF369D000AA8D31 /* previewToUploadFileView.h in Headers */,
+				6B00C7392D3A5E6E00EA2AE2 /* ScanToLoginViewController.h in Headers */,
 				6BD5070E2B9576A4006E7CB0 /* couldPhoneFileListModel.h in Headers */,
 				6B07E0AE2C3D1ED5004A3238 /* nasLastFileViewController.h in Headers */,
 				6BD5070F2B9576A4006E7CB0 /* fileTransferPathCheckViewController.h in Headers */,
@@ -5067,6 +5077,7 @@
 				6B7EA7AD2BF72D3B002D5CC2 /* queryShareModel.m in Sources */,
 				6B8A5AE22C3BCC0E00E40B19 /* lastFileModel.m in Sources */,
 				6B2C1E932C070ADE00FDCF82 /* ZFPlayerLogManager.m in Sources */,
+				6B00C7382D3A5E6E00EA2AE2 /* ScanToLoginViewController.m in Sources */,
 				6B679E012C255DC900D0DC03 /* MineCommonUsedView.m in Sources */,
 				6BD507172B9576A4006E7CB0 /* fileTransferPopView.m in Sources */,
 				6BD507182B9576A4006E7CB0 /* Reachability.m in Sources */,
@@ -5445,6 +5456,7 @@
 				6B7EA7AB2BF72D3B002D5CC2 /* queryShareModel.m in Sources */,
 				6B8A5AE12C3BCC0E00E40B19 /* lastFileModel.m in Sources */,
 				6B2C1E922C070ADE00FDCF82 /* ZFPlayerLogManager.m in Sources */,
+				6B00C7362D3A5E6E00EA2AE2 /* ScanToLoginViewController.m in Sources */,
 				6B679DFF2C255DC900D0DC03 /* MineCommonUsedView.m in Sources */,
 				6B5B60612B3BC8DE009A2AE2 /* fileTransferPopView.m in Sources */,
 				6BF52C962AD5546500A617DB /* Reachability.m in Sources */,

+ 118 - 2
创维盒子/双子星云手机/Class/Guide/LoginType1ViewController.m

@@ -6,6 +6,8 @@
 //
 
 #import "LoginType1ViewController.h"
+#import "ScanToLoginViewController.h"
+#import "GuideViewController.h"
 
 @interface LoginType1ViewController ()<UITextViewDelegate,UITextFieldDelegate>
 @property(nonatomic,strong) UITextField *accountTF;
@@ -74,6 +76,7 @@
     
     UIButton *scanBut = [[UIButton alloc] init];
     [scanBut setImage:[UIImage imageNamed:@"login_scan"] forState:UIControlStateNormal];
+    [scanBut addTarget:self action:@selector(didClickScanButtonFun:) forControlEvents:UIControlEventTouchUpInside];
     [bgView addSubview:scanBut];
     //scanBut.backgroundColor = [UIColor greenColor];
     
@@ -88,7 +91,7 @@
     _accountTF.textColor = [UIColor blackColor];
     _accountTF.font = [UIFont systemFontOfSize:12];
     _accountTF.delegate = self;
-    //_accountTF.keyboardType = UIKeyboardTypeDecimalPad;
+    _accountTF.keyboardType = UIKeyboardTypeNamePhonePad;
     [bgView addSubview:_accountTF];
     
     [_accountTF mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -236,10 +239,29 @@
     return YES;
 }
 
+- (void)textFieldDidEndEditing:(UITextField *)textField
+{
+    [self checkLoginButCanClickFun];
+}
+
 #pragma mark 点击登录
-- (void)didClickButtonFun:(UIButton*)but
+- (void)didClickScanButtonFun:(UIButton*)but
 {
+    ScanToLoginViewController *vc =[ScanToLoginViewController new];
+    [self.navigationController pushViewController:vc animated:YES];
+    
+    KWeakSelf
+    vc.didScanSNFun = ^(NSString * _Nonnull curSnStr) {
+        weakSelf.accountTF.text = curSnStr;
+        [weakSelf checkLoginButCanClickFun];
+    };
+}
 
+#pragma mark 点击登录
+- (void)didClickButtonFun:(UIButton*)but
+{
+    NSString *trimmedText = [_accountTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+    [self checkSNFunBy:trimmedText];
 }
 
 #pragma mark 点击协议
@@ -265,4 +287,98 @@
         }
     }
 }
+
+#pragma mark 验证SN
+- (void)checkSNFunBy:(NSString *)sn{
+    
+    KWeakSelf
+    [[netWorkManager shareInstance] getThridMsgBySN:sn success:^(id  _Nonnull responseObject) {
+        DeviceThirdIdModel *model = responseObject;
+        if([model isKindOfClass:[DeviceThirdIdModel class]]){
+          
+            if(model.status == 0 && model.data){
+                ksharedAppDelegate.DeviceThirdIdMod = model;
+                [weakSelf gotoGuideViewFunBy:sn withResponseObject:model];
+            }
+            else{
+                NSInteger state = 2;
+                if (model.status == 201 || model.status == 202) {
+                    state = model.status;
+                }
+                
+//                if(self->_didScanErrorFun){
+//                    self->_didScanErrorFun(state);
+//                }
+                
+            }
+        }
+        else{
+//            if(self->_didScanErrorFun){
+//                self->_didScanErrorFun(2);
+//            }
+            
+        }
+        
+    } failure:^(NSError * _Nonnull error) {
+//        if(self->_didScanErrorFun){
+//            self->_didScanErrorFun(0);
+//        }
+//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+//            [self.navigationController popViewControllerAnimated:YES];
+//        });
+    }];
+}
+
+#pragma mark GuideViewController
+- (void)gotoGuideViewFunBy:(NSString*)sn withResponseObject:(DeviceThirdIdModel*)DeviceThirdIdMod
+{
+    //数据埋点
+    //[[netWorkManager shareInstance] DataEmbeddingPointBy:0 withEventValue:@"Scan_code"];
+    
+    NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:sn,Const_Have_Add_Device_SN, nil];
+    [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
+    [HWDataManager setBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background) value:YES];
+    
+    //不走引导页
+    [HWDataManager setBoolWithKey:Const_Have_Show_Guide value:YES];
+    
+    /*下一步*/
+//    GuideViewController *nextVC = [[GuideViewController alloc] init];
+//    nextVC.sn = sn;
+//    [self.navigationController pushViewController:nextVC animated:YES];
+    
+    //是否已经有密码了 有就是输入密码 没有就是设置密码
+    NSString *curPwd = DeviceThirdIdMod.data.password;
+    
+    if(curPwd && curPwd.length > 0){
+        BOOL haveOpenMask = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
+        if(!haveOpenMask)
+        {
+            ksharedAppDelegate.isFirstInputPwdDone = YES;
+            [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
+           
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
+            });
+            
+            return;
+        }
+        
+        /*设置密码*/
+//            inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
+//            nextVC.isQRCodeType = YES;
+//            [self.navigationController pushViewController:nextVC animated:YES];
+        
+        [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
+    }
+    else{
+        /*设置密码*/
+//            SetPWDFirstViewController *nextVC = [[SetPWDFirstViewController alloc] init];
+//            [self.navigationController pushViewController:nextVC animated:YES];
+        
+        [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
+    }
+   
+}
+
 @end

+ 16 - 0
创维盒子/双子星云手机/Class/Guide/ScanToLoginViewController.h

@@ -0,0 +1,16 @@
+//
+//  ScanToLoginViewController.h
+//  双子星云手机
+//
+//  Created by xd h on 2025/1/17.
+//
+
+#import "BaseViewController.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ScanToLoginViewController : BaseViewController
+@property (nonatomic,copy) void (^didScanSNFun)(NSString* curSnStr);
+@end
+
+NS_ASSUME_NONNULL_END

+ 451 - 0
创维盒子/双子星云手机/Class/Guide/ScanToLoginViewController.m

@@ -0,0 +1,451 @@
+//
+//  QRCodeScanViewController.m
+//  隐私保护
+//
+//  Created by APPLE on 2023/9/19.
+//
+
+#import "ScanToLoginViewController.h"
+#import <AVFoundation/AVFoundation.h>
+#import <ImageIO/ImageIO.h>
+#import "RSATool.h"
+#import <TZImageManager.h>
+#import <TZImagePickerController.h>
+
+@interface ScanToLoginViewController ()<AVCaptureMetadataOutputObjectsDelegate,AVCaptureVideoDataOutputSampleBufferDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,TZImagePickerControllerDelegate>
+
+@property(nonatomic,strong)AVCaptureVideoPreviewLayer *layer;
+
+//捕捉会话
+@property(nonatomic,strong)AVCaptureSession *session;
+
+//辅助区域框
+@property(nonatomic,strong)UIImageView * cyanEdgeImageView;
+@property(nonatomic,strong)UIImageView * qrCodeScanLine;
+@property(nonatomic,strong)NSTimer * scanLineTimer;
+
+////打开灯光btn,默认为hidden
+//
+//@property(nonatomic,strong)UIButton * lightBtn;
+//
+////获取相册图片进行扫描
+//
+//@property(nonatomic,strong)UIButton * photoBtn;
+@end
+
+@implementation ScanToLoginViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    
+    [self.navigationBar setHidden:YES];
+    [self.toolBar setHidden:YES];
+    
+    AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
+    //判断摄像头状态是否可用
+    if(authStatus==AVAuthorizationStatusAuthorized){
+        [self startScan];
+    }else{
+        NSLog(@"未开启相机权限,请前往设置中开启");
+        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
+            if (granted){
+                mainBlock(^{
+                    [self startScan];
+                });
+            }
+        }];
+    }
+}
+
+-(void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+    if(_scanLineTimer)[_scanLineTimer  invalidate];
+}
+
+//开始扫描二维码
+
+-(void)startScan{
+    //1.创建捕捉会话,AVCaptureSession是第一个要被创建的对象,所有的操作都要基于这一个session
+    self.session = [[AVCaptureSession alloc]init];
+    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
+
+AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
+
+    [self.session addInput:input];
+
+
+
+    //3.添加输出数据(示例对象-->类对象-->元类对象-->根元类对象)
+
+    /*输入的类是AVCaptureInput,那么输出的类相应的就应该是AVCaptureOutput。
+
+ 输出不需要和设备挂钩,因为一般情况下,我们的输出要么是音频或视频文件,要么是一些其他的数据,像二维码扫描一般是字符串类型。
+
+ 所以创建AVCaptureOutput实例就不需要AVCaptureDevice对象。
+
+ AVCaptureOutput也同样是一个抽象类,同样要使用其子类,在这里我们扫描二维码,
+
+ 使用的是AVCaptureMetadataOutput,设置代码如下所示*/
+
+
+    AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
+    [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
+
+    //设置能扫描的区域,这里注意,CGRectMake的x,y和width,height的值是互换位置
+
+    output.rectOfInterest=CGRectMake(250/self.view.frame.size.height, 100/self.view.frame.size.width, (self.view.frame.size.width-200)/self.view.frame.size.width, (self.view.frame.size.width-200)/self.view.frame.size.width);
+
+    [self.session addOutput:output];
+//设置输入元数据的类型(类型是二维码,条形码数据,注意,这个一定要写在添加到session后面,不然要崩溃,如果只需要扫描二维码只需要AVMetadataObjectTypeQRCode,如果还需要扫描条形码,那么全部添加上)
+    [output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode,
+                                     AVMetadataObjectTypeEAN8Code,
+                                     AVMetadataObjectTypeEAN13Code,
+                                     AVMetadataObjectTypeCode39Code,
+                                     AVMetadataObjectTypeCode39Mod43Code,
+                                     AVMetadataObjectTypeCode93Code,
+                                     AVMetadataObjectTypeCode128Code,
+                                     AVMetadataObjectTypePDF417Code,
+                                     AVMetadataObjectTypeAztecCode,
+                                     AVMetadataObjectTypeUPCECode,
+                                     AVMetadataObjectTypeInterleaved2of5Code,
+                                     AVMetadataObjectTypeITF14Code,
+                                     AVMetadataObjectTypeDataMatrixCode,
+                                   ]];
+
+
+
+    //4.添加扫描图层
+
+    self.layer = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
+
+    self.layer.videoGravity=AVLayerVideoGravityResizeAspectFill;
+
+    self.layer.frame = self.view.bounds;
+
+    [self.view.layer addSublayer:self.layer];
+
+
+
+    //5.创建view,通过layer层进行设置边框宽度和颜色,用来辅助展示扫描的区域
+
+    _cyanEdgeImageView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 250, self.view.frame.size.width-200, self.view.frame.size.width-200)];
+
+//    _cyanEdgeImageView.layer.borderWidth=2;
+//
+//    _cyanEdgeImageView.layer.borderColor =[UIColor cyanColor].CGColor;
+
+    _cyanEdgeImageView.image = [UIImage imageNamed:@"qrCode_scan_bg"];
+    [self.view addSubview:_cyanEdgeImageView];
+
+    _qrCodeScanLine=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-200, 1)];
+
+    _qrCodeScanLine.image = [UIImage imageNamed:@"qrCode_scan_line"];
+    [_cyanEdgeImageView addSubview:_qrCodeScanLine];
+
+    _scanLineTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(scanLineDownAndUpFun) userInfo:nil repeats:YES];
+    
+    UILabel *tipLib = [[UILabel alloc] initWithFrame:CGRectMake(20, _cyanEdgeImageView.hw_max_y + 15, SCREEN_W - 40, 20)];
+    tipLib.text = NSLocalizedString(@"guide_qrcoede_tips_please",nil);
+    tipLib.font = [UIFont systemFontOfSize:14.0];
+    tipLib.textAlignment = NSTextAlignmentCenter;
+    tipLib.textColor = [UIColor whiteColor];
+    [self.view addSubview:tipLib];
+    
+    //6.创建检测光感源
+
+    AVCaptureVideoDataOutput *guangOutPut = [[AVCaptureVideoDataOutput alloc] init];
+
+    [guangOutPut setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
+
+    //设置为高质量采集率
+
+    [self.session setSessionPreset:AVCaptureSessionPresetHigh];
+
+    //把光感源添加到会话
+    [self.session addOutput:guangOutPut];
+
+//    self.lightBtn=[[UIButton alloc]initWithFrame:CGRectMake(150, cyanView.frame.origin.y+cyanView.frame.size.height+100, self.view.frame.size.width-300, self.view.frame.size.width-300)];
+//
+//    self.lightBtn.backgroundColor=[UIColor grayColor];
+//
+//    [self.lightBtn addTarget:self action:@selector(lightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
+//
+    
+    //打开相册
+    UIButton *openAlbunBut = [[UIButton alloc] init];
+    [openAlbunBut setTitle:NSLocalizedString(@"guide_qrcoede_open_album",nil) forState:UIControlStateNormal];
+    [openAlbunBut setTitleColor:[UIColor hwColor:@"#3B7FFF" alpha:1.0] forState:UIControlStateNormal];
+    openAlbunBut.titleLabel.font = [UIFont systemFontOfSize:14.0];
+    [openAlbunBut addTarget:self action:@selector(photoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
+    openAlbunBut.backgroundColor = [UIColor hwColor:@"#FFFFFF" alpha:0.2];
+    [self.view addSubview:openAlbunBut];
+    openAlbunBut.layer.cornerRadius = 24;
+    openAlbunBut.layer.masksToBounds = YES;
+    
+    [openAlbunBut mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.width.mas_equalTo(140);
+        make.height.mas_equalTo(48);
+        make.centerX.mas_equalTo(0);
+        make.bottom.mas_equalTo(-80);
+    }];
+    
+    
+//    [self.view addSubview:self.lightBtn];
+//    self.photoBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, self.lightBtn.frame.origin.y+self.lightBtn.frame.size.height+50, self.view.frame.size.width-200, 50)];
+//    [self.photoBtn setTitle:@"相册" forState:UIControlStateNormal];
+//    [self.photoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
+//    self.photoBtn.backgroundColor=[UIColor orangeColor];
+//    [self.photoBtn addTarget:self action:@selector(photoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
+//    [self.view addSubview:self.photoBtn];
+    //9.开始扫描
+    [self.session startRunning];
+    
+    //添加返回键
+    CGFloat btn_w_h  = 40;
+    CGFloat btn_show = 28;
+    UIButton *backBtn = [[UIButton alloc] init];
+    [self.view addSubview:backBtn];
+    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.top.mas_equalTo(H_STATE_BAR + (64.f - btn_w_h)/2.f);
+        make.left.mas_equalTo(10);
+        make.width.mas_equalTo(btn_w_h);
+        make.height.mas_equalTo(btn_w_h);
+    }];
+    [backBtn setImage:[UIImage imageNamed:@"icon_base_back"] forState:(UIControlStateNormal)];
+    [backBtn setImageEdgeInsets:(UIEdgeInsetsMake((btn_w_h - btn_show)/2.f, (btn_w_h - btn_show)/2.f, (btn_w_h - btn_show)/2.f, (btn_w_h - btn_show)/2.f))];
+    [backBtn addTarget:self
+                action:@selector(backBtnPressed)
+      forControlEvents:(UIControlEventTouchUpInside)];
+}
+
+#pragma mark timer 处理线上下移动
+bool isScantoLoginDownType = YES;
+-(void)scanLineDownAndUpFun
+{
+    [UIView animateWithDuration:0.01 animations:^{
+        
+        if(isScantoLoginDownType && self->_qrCodeScanLine.hw_y <= self->_cyanEdgeImageView.hw_h){
+            self->_qrCodeScanLine.hw_y += 2;
+            
+            if(self->_cyanEdgeImageView.hw_h - self->_qrCodeScanLine.hw_y <= 5){
+                isScantoLoginDownType = NO;
+            }
+        }
+        else if(!isScantoLoginDownType && self->_qrCodeScanLine.hw_y >= 0)
+        {
+            self->_qrCodeScanLine.hw_y -= 2;
+            
+            if(self->_qrCodeScanLine.hw_y <= 5){
+                isScantoLoginDownType = YES;
+            }
+        }
+    }];
+}
+
+//实现扫描的回调代理方法
+
+- (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputMetadataObjects:(NSArray*)metadataObjects fromConnection:(AVCaptureConnection*)connection{
+
+//如果数组metadataObjects中有数据,metadataObjects是个数组类型
+
+    if(metadataObjects.count>0) {
+        
+        AVMetadataMachineReadableCodeObject*object = [metadataObjects lastObject];
+        
+        NSLog(@"%@",object.stringValue);
+        
+        /*扫描到有用信息时取消扫描*/
+        NSString *resStr = object.stringValue;//RK3908P1V62112465
+        
+        [self handleScanCodeResultFun:resStr];
+    }
+    else{
+        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
+        NSLog(@"没有扫描到数据");
+    }
+}
+
+#pragma mark 处理扫码出来的数据
+- (void)handleScanCodeResultFun:(NSString*)resultStr
+{
+    NSString * resStr = resultStr;
+    
+    if(resStr.length > 22)
+    {
+        NSString*desStr  = [RSATool AES128Decrypt:resStr key:AESCODEKEEYY];
+        
+        if(desStr){//能解码
+            resStr = desStr;
+        }
+    }
+    //Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=
+    //sgl5OzDoVjY5SmGuL50/EnQ4n6Kw+DzRiE1oUjq7yAM=
+    
+    if (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
+        || resStr.length == @"0333933700223250017273".length
+         ){
+        
+        [_scanLineTimer  invalidate];
+        
+        //停止扫描
+        [self.session stopRunning];
+        
+        //移除扫描层layer
+        [self.layer removeFromSuperlayer];
+        
+        if(_didScanSNFun){
+            _didScanSNFun(resStr);
+        }
+        
+        [self.navigationController popViewControllerAnimated:YES];
+    }
+    else{
+        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
+    }
+
+}
+
+
+//光感传感器代理
+-(void)captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection{
+
+    //获取光线的值
+
+    CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL,sampleBuffer, kCMAttachmentMode_ShouldPropagate);
+
+    NSDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(__bridge NSDictionary*)metadataDict];
+
+    CFRelease(metadataDict);
+
+    NSDictionary *exifMetadata = [[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy];
+
+    float brightnessValue = [[exifMetadata objectForKey:(NSString*)kCGImagePropertyExifBrightnessValue]floatValue];
+
+    NSLog(@"%f",brightnessValue);
+
+
+    // 根据brightnessValue的值来打开和关闭闪光灯,一般值小于0就需要打开,大于0就关闭
+
+//    if((brightnessValue <0)) {//显示闪光灯
+//        self.lightBtn.hidden=NO;
+//    }else if((brightnessValue >0)) {//隐藏闪光灯
+//        self.lightBtn.hidden=YES;
+//    }
+}
+
+////闪光灯按钮点击方法
+//
+//-(void)lightBtnClick:(UIButton*)sender{
+//    //判断当前设备是否有闪光灯
+//
+//    AVCaptureDevice * device=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
+//
+//    BOOL result=[device hasTorch];
+//
+//    if(result==YES){
+//        if(self.lightBtn.isSelected==NO){
+//            self.lightBtn.selected=YES;
+//            self.lightBtn.backgroundColor=[UIColor greenColor];
+//            [device lockForConfiguration:nil];
+//            [device setTorchMode: AVCaptureTorchModeOn];//开
+//            [device unlockForConfiguration];
+//        }else if(self.lightBtn.isSelected==YES){
+//            self.lightBtn.selected=NO;
+//            self.lightBtn.backgroundColor=[UIColor grayColor];
+//            [device lockForConfiguration:nil];
+//            [device setTorchMode: AVCaptureTorchModeOff];//关
+//            [device unlockForConfiguration];
+//        }
+//    }else{
+//        NSLog(@"当前设备闪光灯不可用");
+//    }
+//}
+//
+////获取相册图片btn点击方法
+
+-(void)photoBtnClick:(UIButton*)sender{
+//    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
+//    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
+//    // imagePicker.allowsEditing = YES;
+//    imagePicker.delegate=self;
+//    [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
+    
+    [self photoClickFun];
+}
+
+- (void)photoClickFun
+{
+    TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
+
+    imagePicker.allowPickingVideo=NO;
+    //imagePicker.isStatusBarDefault=YES;
+    imagePicker.allowTakePicture=NO;
+    imagePicker.allowPreview = NO;
+    // 4. 照片排列按修改时间升序
+    imagePicker.sortAscendingByModificationDate = YES;
+    [self presentViewController:imagePicker animated:YES completion:nil];
+
+}
+
+- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto
+{
+    if(photos && photos.count >= 1){
+        [self detectImageFunBy:photos.firstObject];
+    }
+    else{
+        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
+    }
+}
+
+//UIImagePickerControllerDelegate选择图片的回调
+
+-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
+    //把UIimage类型转换成CIimage类型
+    UIImage *pickedImage = info[UIImagePickerControllerEditedImage] ?: info[UIImagePickerControllerOriginalImage];
+    
+    [picker dismissViewControllerAnimated:YES completion:^{
+        
+    }];
+    
+    [self detectImageFunBy:pickedImage];
+}
+
+
+#pragma mark 解析Uiimage
+- (void)detectImageFunBy:(UIImage*)pickedImage
+{
+    CIImage*detectImage = [CIImage imageWithData:UIImagePNGRepresentation(pickedImage)];
+    //解析扫描二维码结果字符串
+    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy: CIDetectorAccuracyLow}];
+    //CIQRCodeFeature*feature = (CIQRCodeFeature*)[detector featuresInImage:detectImage options:nil].firstObject;
+    NSArray *messageStringArr = (CIQRCodeFeature*)[detector featuresInImage:detectImage options:nil];
+    
+    //排除掉 http的
+    __block NSString *curQRCodeStr = nil;
+    for(CIQRCodeFeature*feature in messageStringArr){
+       
+        if([feature.messageString  rangeOfString:@"http"].location == NSNotFound){
+            curQRCodeStr = feature.messageString;
+            break;
+        }
+    }
+    
+    if(curQRCodeStr) {
+        NSLog(@"=================二维码结果为%@",curQRCodeStr);
+        [self handleScanCodeResultFun:curQRCodeStr];
+
+    }else{
+        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
+        NSLog(@"没有扫描到数据");
+    }
+    
+//        //停止会话对象扫描
+//        [self.session stopRunning];
+//        //移除扫描层layer
+//        [self.layer removeFromSuperlayer];
+    
+}
+
+@end