Quellcode durchsuchen

1.扫码添加相册

huangxiaodong vor 1 Jahr
Ursprung
Commit
a35947104f

+ 75 - 44
创维盒子/双子星云手机/Class/Guide/QRCodeScanViewController.m

@@ -32,7 +32,6 @@
 ////获取相册图片进行扫描
 //
 //@property(nonatomic,strong)UIButton * photoBtn;
-
 @end
 
 @implementation QRCodeScanViewController
@@ -174,6 +173,26 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
 //
 //    [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];
@@ -224,43 +243,52 @@ bool isDownType = YES;
         /*扫描到有用信息时取消扫描*/
         NSString *resStr = object.stringValue;//RK3908P1V62112465
         
-        if(resStr.length > 22)
-        {
-            NSString*desStr  = [RSATool AES128Decrypt:resStr key:AESCODEKEEYY];
-            
-            if(desStr){//能解码
-                resStr = desStr;
-            }
-        }
-        //Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=
-        //sgl5OzDoVjY5SmGuL50/EnQ4n6Kw+DzRiE1oUjq7yAM=
+        [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 (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
-            || resStr.length == @"0333933700223250017273".length
-             ){
-            
-            [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
-            [_scanLineTimer  invalidate];
-            
-            NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:resStr,Const_Have_Add_Device_SN, nil];
-            [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
-            
-            [self nextStep:resStr];
-            
-            //停止扫描
-            [self.session stopRunning];
-            
-            //移除扫描层layer
-            [self.layer removeFromSuperlayer];
+        if(desStr){//能解码
+            resStr = desStr;
         }
-    }else{
+    }
+    //Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=
+    //sgl5OzDoVjY5SmGuL50/EnQ4n6Kw+DzRiE1oUjq7yAM=
+    
+    if (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
+        || resStr.length == @"0333933700223250017273".length
+         ){
         
-        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
-        NSLog(@"没有扫描到数据");
+        [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
+        [_scanLineTimer  invalidate];
         
+        NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:resStr,Const_Have_Add_Device_SN, nil];
+        [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
+        
+        [self nextStep:resStr];
+        
+        //停止扫描
+        [self.session stopRunning];
+        
+        //移除扫描层layer
+        [self.layer removeFromSuperlayer];
     }
+
 }
 
+
 - (void)nextStep:(NSString *)sn{
     /*下一步*/
     GuideViewController *nextVC = [[GuideViewController alloc] init];
@@ -325,14 +353,14 @@ bool isDownType = YES;
 //}
 //
 ////获取相册图片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];
-//}
+
+-(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];
+}
 
 //UIImagePickerControllerDelegate选择图片的回调
 
@@ -346,13 +374,16 @@ bool isDownType = YES;
     [picker dismissViewControllerAnimated:YES completion:^{
         if(feature.messageString) {
             NSLog(@"=================二维码结果为%@",feature.messageString);
+            [self handleScanCodeResultFun:feature.messageString];
+            
         }else{
-            NSLog(@"未扫描到相应二维码");
+            [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
+            NSLog(@"没有扫描到数据");
         }
-        //停止会话对象扫描
-        [self.session stopRunning];
-        //移除扫描层layer
-        [self.layer removeFromSuperlayer];
+//        //停止会话对象扫描
+//        [self.session stopRunning];
+//        //移除扫描层layer
+//        [self.layer removeFromSuperlayer];
     }];
 }
 

+ 101 - 77
创维盒子/双子星云手机/Class/Set/ChangeDevice/QRCodeScanForChangeDeviceViewController.m

@@ -177,6 +177,25 @@ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
 //
 //    [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)];
+    
+    //打开相册
+    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.photoBtn setTitle:@"相册" forState:UIControlStateNormal];
 //    [self.photoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
 //    self.photoBtn.backgroundColor=[UIColor orangeColor];
@@ -225,81 +244,83 @@ bool isDownType22 = YES;
         
         /*扫描到有用信息时取消扫描*/
         NSString *resStr = object.stringValue;//RK3908P1V62112465
-        if(resStr.length > 22)
-        {
-            NSString*desStr  = [RSATool AES128Decrypt:resStr key:AESCODEKEEYY];
-            
-            if(desStr){//能解码
-                resStr = desStr;
-            }
+        [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=
+    }
+    //Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=
+    //sgl5OzDoVjY5SmGuL50/EnQ4n6Kw+DzRiE1oUjq7yAM=
+    
+    if (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
+        || resStr.length == @"0333933700223250017273".length
+         ){
         
-        if (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
-            || resStr.length == @"0333933700223250017273".length
-             ){
-            
-            NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
-            if (!deviceDict || [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
-                NSString *oldStr = deviceDict[Const_Have_Add_Device_SN];
-                if([oldStr isEqualToString:resStr]){
-                    [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_change_same",nil)] show];
-                    
-                    //停止扫描
-                    [self.session stopRunning];
-                    
-                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-                        [self.session startRunning];
-                    });
-                    
-                    return;
-                }
-            }
+        NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
+        if (!deviceDict || [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
+            NSString *oldStr = deviceDict[Const_Have_Add_Device_SN];
+            if([oldStr isEqualToString:resStr]){
+                [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_change_same",nil)] show];
                 
+                //停止扫描
+                [self.session stopRunning];
+                
+                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                    [self.session startRunning];
+                });
+                
+                return;
+            }
+        }
             
-            //[[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
-            [_scanLineTimer  invalidate];
-            
-            //停止扫描
-            [self.session stopRunning];
-            
-            //移除扫描层layer
-            [self.layer removeFromSuperlayer];
+        
+        //[[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
+        [_scanLineTimer  invalidate];
+        
+        //停止扫描
+        [self.session stopRunning];
+        
+        //移除扫描层layer
+        [self.layer removeFromSuperlayer];
+        
+
+        
+        [self showNewIndicatorHaveStrWithCanBack:NO canTouch:NO showText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)];
+        [[connectDeviceManager shareInstance] getThridMsgBySN:resStr needReconnect:YES didNetEnd:^(bool didSuc) {
             
-//            for (UIViewController *vc in [self.navigationController viewControllers]) {
-//                if ([vc isKindOfClass:[MySetViewController class]]){
-//                    [self.navigationController popToViewController:vc animated:YES];
-//                    break;
-//                }
-//            }
+            [self removeNewIndicatorHaveStr];
             
-            [self showNewIndicatorHaveStrWithCanBack:NO canTouch:NO showText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)];
-            [[connectDeviceManager shareInstance] getThridMsgBySN:resStr needReconnect:YES didNetEnd:^(bool didSuc) {
+            if(didSuc){
                 
-                [self removeNewIndicatorHaveStr];
+                NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
+                [dict setObject:resStr forKey:Const_Have_Add_Device_SN];
+                [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
                 
-                if(didSuc){
-                    
-                    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
-                    [dict setObject:resStr forKey:Const_Have_Add_Device_SN];
-                    [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
-                    
-                    [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
-                }else{
-                    [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_get_SdnID_fail",nil)] show];
-                    
-                    [self.navigationController popViewControllerAnimated:YES];
-                }
-            }];
-        }
-    }else{
-        //[[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
-        NSLog(@"没有扫描到数据");
+                [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
+            }else{
+                [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_get_SdnID_fail",nil)] show];
+                
+                [self.navigationController popViewControllerAnimated:YES];
+            }
+        }];
     }
 }
 
-
 //光感传感器代理
 -(void)captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection{
 
@@ -356,14 +377,14 @@ bool isDownType22 = YES;
 //}
 //
 ////获取相册图片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];
-//}
+
+-(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];
+}
 
 //UIImagePickerControllerDelegate选择图片的回调
 
@@ -377,13 +398,16 @@ bool isDownType22 = YES;
     [picker dismissViewControllerAnimated:YES completion:^{
         if(feature.messageString) {
             NSLog(@"=================二维码结果为%@",feature.messageString);
+            [self handleScanCodeResultFun:feature.messageString];
+            
         }else{
-            NSLog(@"未扫描到相应二维码");
+            [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
+            NSLog(@"没有扫描到数据");
         }
-        //停止会话对象扫描
-        [self.session stopRunning];
-        //移除扫描层layer
-        [self.layer removeFromSuperlayer];
+//        //停止会话对象扫描
+//        [self.session stopRunning];
+//        //移除扫描层layer
+//        [self.layer removeFromSuperlayer];
     }];
 }
 

+ 2 - 0
创维盒子/双子星云手机/zh-Hans.lproj/Localizable.strings

@@ -238,3 +238,5 @@
 
 "input_pwd_forget_pwd" = "忘记密码";
 "input_pwd_forget_secret_key" = "忘记秘钥";
+
+"guide_qrcoede_open_album" = "打开相册";